Skip to content

Commit 49c0f37

Browse files
committed
2week
1 parent dc82596 commit 49c0f37

File tree

6 files changed

+166
-0
lines changed

6 files changed

+166
-0
lines changed

02-240326/yunjaeeun44/A.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
n, m = map(int, input().split())
2+
answer = 1
3+
for i in range(m):
4+
answer *= n-i
5+
for i in range(1, m+1):
6+
answer = answer // i
7+
print(answer)

02-240326/yunjaeeun44/B.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
N = int(input())
2+
A = list(map(int, input().split()))
3+
add, sub, mul, div = map(int, input().split());
4+
max_result = - int(1e9)
5+
min_result = int(1e9)
6+
7+
def dfs(add, sub, mul, div, sum, idx):
8+
global max_result, min_result
9+
if idx == N:
10+
max_result = max(max_result, sum)
11+
min_result = min(min_result, sum)
12+
return
13+
if add:
14+
dfs(add-1, sub, mul, div, sum + A[idx], idx + 1)
15+
if sub:
16+
dfs(add, sub-1, mul, div, sum - A[idx], idx + 1)
17+
if mul:
18+
dfs(add, sub, mul-1, div, sum * A[idx], idx + 1)
19+
if div:
20+
dfs(add, sub, mul, div-1, int(sum / A[idx]), idx + 1)
21+
22+
dfs(add, sub, mul, div, A[0], 1)
23+
print(max_result)
24+
print(min_result)

02-240326/yunjaeeun44/C.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import sys
2+
from collections import deque
3+
4+
def fire_move():
5+
size = len(fires)
6+
while size:
7+
x, y = fires.popleft()
8+
for ddx, ddy in zip(dx, dy):
9+
nx = x + ddx
10+
ny = y + ddy
11+
if 0 <= nx < w and 0 <= ny < h and building[ny][nx] == '.':
12+
fires.append([nx, ny])
13+
building[ny][nx] = '*'
14+
size -= 1
15+
16+
def BFS():
17+
while sanggeuns:
18+
fire_move()
19+
size = len(sanggeuns)
20+
while size:
21+
x, y, sec = sanggeuns.popleft()
22+
for ddx, ddy in zip(dx, dy):
23+
nx = x + ddx
24+
ny = y + ddy
25+
if 0 <= nx < w and 0 <= ny < h:
26+
if building[ny][nx] == '.' and visit[ny][nx]==0:
27+
sanggeuns.append([nx, ny, sec+1])
28+
visit[ny][nx] = 1
29+
else:
30+
return sec + 1
31+
size -= 1
32+
return 0
33+
34+
35+
36+
input = sys.stdin.readline
37+
38+
dx = [0,1,-1,0]
39+
dy = [1,0,0,-1]
40+
41+
building = [] #불 실시간 반영
42+
fires = deque(list()) #다음에 번질 불의 위치들을 담는 큐
43+
sanggeuns = deque(list()) #[상근이의 위치, 탈출한 시간]을 담는 큐
44+
45+
T = int(input())
46+
for _ in range(T):
47+
w, h = map(int, input().split())
48+
building.clear()
49+
fires.clear()
50+
sanggeuns.clear()
51+
visit = [[0]*w for _ in range(h)]
52+
53+
for y in range(h):
54+
building.append(list(input()))
55+
for x in range(w):
56+
if building[y][x] == '@':
57+
sanggeuns.append([x, y, 0])
58+
visit[y][x] = 1
59+
building[y][x] == '.'
60+
if building[y][x] == '*':
61+
fires.append([x, y])
62+
63+
result = BFS()
64+
if result == 0:
65+
print("IMPOSSIBLE")
66+
else:
67+
print(result)
68+

02-240326/yunjaeeun44/D.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import sys
2+
#input = sys.stdin.readline
3+
4+
S = input()
5+
duck = ['q','u','a','c','k']
6+
ducks = [[]]
7+
valid = True
8+
9+
def main():
10+
for sound in S:
11+
put = False
12+
idx = duck.index(sound)
13+
for i in ducks:
14+
if len(i)%5 == idx:
15+
i.append(sound)
16+
put = True
17+
break
18+
if put == False and idx == 0:
19+
ducks.append(['q'])
20+
put = True
21+
elif put == False:
22+
print(-1)
23+
return 0
24+
25+
for i in ducks:
26+
if len(i)%5 != 0:
27+
print(-1)
28+
return 0
29+
print(len(ducks))
30+
31+
main()

02-240326/yunjaeeun44/E.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
N, K = map(int, input().split())
2+
nums = list(map(int, input().split()))
3+
left, right, answer = 0, 0, 0
4+
dic = {}
5+
6+
while right < N:
7+
if not dic.get(nums[right]):
8+
dic[nums[right]] = 1
9+
right += 1
10+
elif dic.get(nums[right]) < K:
11+
dic[nums[right]] = dic[nums[right]] + 1
12+
right += 1
13+
else:
14+
dic[nums[left]] = dic[nums[left]] - 1
15+
left += 1
16+
answer = max(answer, right - left)
17+
print(answer)
18+

02-240326/yunjaeeun44/F.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
def check(phone_nums, N):
5+
for i in range(N-1):
6+
if phone_nums[i] == phone_nums[i+1][:len(phone_nums[i])]:
7+
print("NO")
8+
return 0
9+
print("YES")
10+
11+
T = int(input())
12+
for _ in range(T):
13+
N = int(input())
14+
phone_nums = []
15+
for i in range(N):
16+
phone_nums.append(input().rstrip())
17+
phone_nums.sort()
18+
check(phone_nums, N)

0 commit comments

Comments
 (0)