Skip to content

Commit 524ec79

Browse files
authored
Merge pull request #104 from zaqquum/main
Hongjoo / 12์›” 2์ฃผ์ฐจ / 2๋ฌธ์ œ
2 parents a1ca274 + 2d240ea commit 524ec79

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""2024.12.14, 30min , #๊ตฌํ˜„"""
2+
def solution(record):
3+
answer = []
4+
# 1. history์™€ user_db DB ์ •์˜
5+
user_db = {} # key=uid , value = username
6+
history = [] # ["Enter / Leave" , uid ]
7+
8+
#2. history์™€ user_db ๊ธฐ๋ก ์‹œ์ž‘
9+
for r in record :
10+
command = r.split() # command = [๋™์‚ฌV ,userid ,(username)]
11+
v = command[0]
12+
uid = command[1]
13+
# 2-1 Enter : user_db ์ถ”๊ฐ€ , history ์ถ”๊ฐ€
14+
if v == 'Enter' :
15+
user_db[uid] = command[2] # user_db[uid] = username
16+
history.append([uid ,v]) # history: [uid , "Enter" ]
17+
#2-2 Leave :history ์ถ”๊ฐ€
18+
elif v == 'Leave':
19+
history.append([uid,v]) # history: [uid , "Leave" ]
20+
#2-3 Change : user_db ์ˆ˜์ •(username ๋ณ€๊ฒฝ)
21+
elif v == 'Change':
22+
user_db[uid] = command[2] #user_db[uid] = new_username
23+
24+
# 3.user_db, histoy ๊ธฐ๋ฐ˜์œผ๋กœ ๋ฌธ์ž์—ด ๋ฐฐ์—ด result๋ฅผ ๋งŒ๋“ค๊ธฐ
25+
result = list()
26+
# ์˜์–ด v ์„ ํ•œ๊ตญ์–ด ๋™์‚ฌ๋กœ ๋ฒˆ์—ญ
27+
en_to_ko = {'Enter':'๋“ค์–ด์™”์Šต๋‹ˆ๋‹ค.','Leave' : '๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค.'}
28+
for uid , h_v in history :
29+
user_name = user_db[uid]
30+
result.append(f"{user_name}๋‹˜์ด {en_to_ko[h_v]}" )
31+
32+
return result
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""
2+
2024.12.14, ๊ณผ์ œ๋ฌธ์ œ, 2hour
3+
"""
4+
5+
import sys
6+
7+
#0. ์ž…๋ ฅ ๋ณ€์ˆ˜๋ฅผ ํ†ตํ•ด ๊ฐ ์นธ์— ์ •์ˆ˜๊ฐ’์„ ๊ฐ€์ง€๋Š” NxM ํ–‰ graph ์ •์˜
8+
N,M = map(int,sys.stdin.readline().split())
9+
graph=[[0 for _ in range(M)] for k in range(N)]
10+
for i in range(N) :
11+
graph[i] = list( map(int,sys.stdin.readline().split()))
12+
13+
max_num = 0
14+
#2. graph ๋‚ด ํŠน์ • ์นธ(์ ˆ๋Œ€์ขŒํ‘œ , (row,col)) ๊ธฐ์ค€์—์„œ
15+
#๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” 19๊ฐœ ํ˜•ํƒœ์˜ ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ ์˜์—ญ ์† ์ •์ˆ˜๋“ค์˜ ํ•ฉ์˜ ์ตœ๋Œ€ ๊ฐ’ ์ฐพ๊ธฐ
16+
#ํ•จ์ˆ˜ ๋‚ด๋ถ€์—์„  ์ƒ๋Œ€์ขŒํ‘œ(r,c)๋กœ ์นธ์˜ ์œ„์น˜ ํŒŒ์•…
17+
def tetries_sum (row,col):
18+
sub_maxsum = 0
19+
#2-1. 19๊ฐœ ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ๋Š” ํฌ๊ฒŒ 4๊ฐ€์ง€ ์ง์‚ฌ๊ฐํ˜• ํ˜•ํƒœ์˜ ์˜์—ญ์œผ๋กœ ์†Œ๋ถ„๋ฅ˜
20+
for n,m in [[1,4],[2,3],[3,2],[4,1]]:
21+
sub_sum=0 # ํŠน์ • ์นธ(row,col)์—์„œ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” ์ •์ˆ˜ํ•ฉ ์ค‘ ์ตœ๋Œ€๊ฐ’
22+
23+
#2-2. 19๊ฐœ ์ค‘ graph(NxM) ์•ˆ์—์„œ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ๋งŒ ์ ์šฉ
24+
if row>=0 and row + n <=N and col>=0 and col+m <=M :
25+
#(1) ์ง์‚ฌ๊ฐํ˜•(4๊ฐ€์ง€) ์˜์—ญ๋‚ด ๋ชจ๋“  ์ •์ˆ˜๊ฐ’๋“ค์˜ ํ•ฉ
26+
for r in range(n):
27+
for c in range(m):
28+
29+
sub_sum +=graph[row + r][col+ c]
30+
#(2) 2x3 ๊ณผ 3x2 ํ˜•ํƒœ ์˜์—ญ ์ค‘ ๋น ์ ธ์•ผ ํ•˜๋Š” 2๊ฐœ ์นธ๋“ค์˜ ์ •์ˆ˜๊ฐ’์˜ ํ•ฉ ๊ตฌํ•˜๊ธฐ
31+
if n==2 and m==3 or n==3 and m==2 :
32+
del_tmp = list()
33+
#a. 2x3 ์ง์‚ฌ๊ฐํ˜• ์˜์—ญ ์ค‘ ๋น ์ ธ์•ผ ํ•˜๋Š” 2๊ฐœ ์นธ๋“ค์˜ ์กฐํ•ฉ(์ƒ๋Œ€์ขŒํ‘œ) : 10๊ฐœ
34+
if n == 2 and m == 3 :
35+
del_candidates = [[[0,0],[0,1]],[[0,1],[0,2]],[[1,0],[1,1]],[[1,1],[1,2]],
36+
[[0,0],[1,0]],[[0,2],[1,2]],[[0,0],[1,2]],[[0,2],[1,0]],[[0,0],[0,2]],[[1,0],[1,2]]
37+
]
38+
#b. 3x2 ์ง์‚ฌ๊ฐํ˜• ์˜์—ญ ์ค‘ ๋น ์ ธ์•ผ ํ•˜๋Š” 2๊ฐœ ์นธ๋“ค์˜ ์กฐํ•ฉ(์ƒ๋Œ€์ขŒํ‘œ) : 10๊ฐœ
39+
elif n==3 and m == 2 :
40+
del_candidates = [[[0,0],[0,1]],
41+
[[0,0],[1,0]],[[0,1],[1,1]],[[1,0],[2,0]],[[1,1],[2,1]],[[2,0],[2,1]],
42+
[[0,0],[2,1]],[[2,0],[0,1]],[[0,0],[2,0]],[[0,1],[2,1]]]
43+
#(3) ๋นผ์•ผํ•˜๋Š” 2๊ฐœ ์นธ๋“ค์˜ ์กฐํ•ฉ๋“ค(10์ข…๋ฅ˜)์— ๋Œ€ํ•ด ์ •์ˆ˜๊ฐ’์˜ ํ•ฉ ๊ตฌํ•˜๊ธฐ
44+
for n1,n2 in del_candidates:
45+
del_tmp.append(graph[row +n1[0]][col+ n1[1]] +graph[row+n2[0]][col+n2[1]])
46+
#(4) 2x3 ๋˜๋Š” 3x2 ์˜์—ญ์—์„œ ํ•ฉ์˜ ์ตœ๋Œ€๊ฐ’์„ ๊ตฌํ•˜๊ธฐ ์œ„ํ•ด 10๊ฐœ์˜ ๋บ„ ๊ฐ’ ์ค‘ ์ตœ์†Œ๊ฐ’์œผ๋กœ ๋นผ๊ธฐ
47+
sub_sum -= min(del_tmp)
48+
49+
sub_maxsum = max(sub_maxsum , sub_sum) # ์ตœ๋Œ€๊ฐ’ ์—…๋ฐ์ดํŠธ
50+
51+
52+
else : #ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ๊ฐ€ graph ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚จ -> skip
53+
continue
54+
return sub_maxsum # ์ ˆ๋Œ€์ขŒํ‘œ(row,col) ์นธ ๊ธฐ์ค€์—์„œ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” ํ•ฉ์˜ ์ตœ๋Œ€
55+
56+
max_sum = 0 #์ „์ฒด graph ๋‚ด ํ•ฉ์˜ ์ตœ๋Œ€๊ฐ’
57+
# 1. graph ๋‚ด ๋ชจ๋“  ์นธ์„ ์ˆœํšŒ
58+
for i in range(N) :
59+
for j in range(M) :
60+
new_sub_sum=tetries_sum(i,j) # 2. ์ ˆ๋Œ€ ์ขŒํ‘œ(i,j) ์นธ ๊ธฐ์ค€์—์„œ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” ํ•ฉ์˜ ์ตœ๋Œ€ ๊ฐ’ ๊ณ„์‚ฐ
61+
max_sum= max(max_sum,new_sub_sum) #3.์ „์ฒด graph ๋‚ด ํ•ฉ์˜ ์ตœ๋Œ€๊ฐ’ ์—…๋ฐ์ดํŠธ
62+
print(max_sum)

0 commit comments

Comments
ย (0)