Skip to content

Commit 20d99a3

Browse files
authored
Merge pull request #54 from 24-Algorithm/minjeong
Minjeong / 8์›” 3์ฃผ์ฐจ / 5๋ฌธ์ œ
2 parents 41f19ff + 4b3eae4 commit 20d99a3

5 files changed

+153
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
n = int(input())
5+
answer = []
6+
7+
limit = 10 ** (len(str(n)) // 2 + 1) # ๋ฐ˜๋ณต ๋ฒ”์œ„ ์„ค์ • (n์˜ ์ž๋ฆฟ์ˆ˜์˜ ์ ˆ๋ฐ˜์—์„œ 1์„ ๋”ํ•œ ๊ฐ’์„ 10์˜ ์ง€์ˆ˜)
8+
9+
# ํšŒ๋ฌธ์ˆ˜๋ฅผ ์ƒ์„ฑํ•˜์—ฌ n๊ณผ ๋น„๊ต
10+
for i in range(1, limit):
11+
half = str(i)
12+
13+
# ์ง์ˆ˜ ์ž๋ฆฌ์ˆ˜ ํšŒ๋ฌธ์ˆ˜
14+
p_even = int(half + half[::-1])
15+
if p_even <= n:
16+
answer.append(p_even)
17+
18+
# ํ™€์ˆ˜ ์ž๋ฆฌ์ˆ˜ ํšŒ๋ฌธ์ˆ˜
19+
p_odd = int(half + half[-2::-1])
20+
if p_odd <= n:
21+
answer.append(p_odd)
22+
23+
print(len(answer))
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import sys
2+
from collections import deque
3+
input = sys.stdin.readline
4+
5+
def bfs(x, y):
6+
queue = deque([(x, y)])
7+
union = [(x, y)] # ์—ฐํ•ฉ์— ํฌํ•จ๋œ ๋‚˜๋ผ๋“ค์„ ์ €์žฅํ•  ๋ฆฌ์ŠคํŠธ
8+
visited[x][y] = 1 # ํ˜„์žฌ ๋‚˜๋ผ๋ฅผ ๋ฐฉ๋ฌธ ํ‘œ์‹œ
9+
total_population = nation[x][y] # ์—ฐํ•ฉ์˜ ์ด ์ธ๊ตฌ ์ˆ˜
10+
11+
while queue:
12+
x, y = queue.popleft() # ํ์—์„œ ํ•˜๋‚˜์˜ ๋‚˜๋ผ๋ฅผ ๊บผ๋ƒ„
13+
for nx, ny in ((-1, 0), (1, 0), (0, -1), (0, 1)): # ์ธ์ ‘ํ•œ ๋„ค ๋ฐฉํ–ฅ ํ™•์ธ
14+
dx, dy = x + nx, y + ny
15+
# ๋ฒ”์œ„ ๋‚ด์— ์žˆ๊ณ , ์•„์ง ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ ๊ณณ์ด๋ผ๋ฉด
16+
if (0 <= dx < N and 0 <= dy < N) and visited[dx][dy] == 0:
17+
# ๋‘ ๋‚˜๋ผ์˜ ์ธ๊ตฌ์˜ ์ฐจ์ด๊ฐ€ L์ด์ƒ R์ดํ•˜๋ผ๋ฉด(=์—ฐํ•ฉ์ด ๋œ๋‹ค๋ฉด)
18+
if L <= abs(nation[dx][dy] - nation[x][y]) <= R:
19+
visited[dx][dy] = 1 # ๋ฐฉ๋ฌธ ํ‘œ์‹œ
20+
queue.append((dx, dy)) # ํ์— ์ถ”๊ฐ€
21+
union.append((dx, dy)) # ์—ฐํ•ฉ์— ์ถ”๊ฐ€
22+
total_population += nation[dx][dy] # ์—ฐํ•ฉ ์ธ๊ตฌ ์ถ”๊ฐ€
23+
24+
# ์—ฐํ•ฉ์ด 2๊ฐœ ์ด์ƒ์˜ ๋‚˜๋ผ๋กœ ์ด๋ฃจ์–ด์กŒ์„ ๊ฒฝ์šฐ
25+
if len(union) > 1:
26+
new_population = total_population // len(union) # ์ƒˆ๋กœ์šด ์ธ๊ตฌ ์ˆ˜ ๊ณ„์‚ฐ
27+
for i, j in union:
28+
nation[i][j] = new_population # ์—ฐํ•ฉ ๋‚ด์˜ ๋ชจ๋“  ๋‚˜๋ผ์— ์ธ๊ตฌ ์žฌ๋ฐฐ์น˜
29+
return True # ์ธ๊ตฌ ์ด๋™์ด ์ผ์–ด๋‚ฌ์Œ
30+
31+
return False # ์ธ๊ตฌ ์ด๋™์ด ์ผ์–ด๋‚˜์ง€ ์•Š์Œ
32+
33+
N, L, R = map(int, input().split())
34+
nation = [list(map(int, input().split())) for _ in range(N)]
35+
day = 0 # ์ธ๊ตฌ์ด๋™ ๋ฐœ์ƒ ์ผ์ˆ˜
36+
37+
while True:
38+
visited = [[0] * N for _ in range(N)]
39+
is_moved = False # ์ธ๊ตฌ ์ด๋™์ด ๋ฐœ์ƒํ–ˆ๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ์ €์žฅํ•  ๋ณ€์ˆ˜
40+
41+
# ๋ชจ๋“  ๋‚˜๋ผ๋ฅผ ํƒ์ƒ‰ํ•˜๋ฉฐ ์—ฐํ•ฉ ํ˜•์„ฑ, ์ธ๊ตฌ ์ด๋™ ํ™•์ธ
42+
for i in range(N):
43+
for j in range(N):
44+
if not visited[i][j]: # ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ ๋‚˜๋ผ์—์„œ BFS ์‹œ์ž‘
45+
visited[i][j] = 1 # ๋ฐฉ๋ฌธ ํ‘œ์‹œ
46+
if bfs(i, j): # ํ•œ ๋ฒˆ์ด๋ผ๋„ ์ธ๊ตฌ ์ด๋™์ด ๋ฐœ์ƒํ–ˆ๋‹ค๋ฉด
47+
is_moved = True # ์ธ๊ตฌ ์ด๋™์ด ๋ฐœ์ƒํ–ˆ์Œ์„ ํ‘œ์‹œ
48+
49+
if not is_moved: # ์ธ๊ตฌ ์ด๋™์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š์•˜๋‹ค๋ฉด ์ข…๋ฃŒ
50+
break
51+
52+
day += 1 # ์ธ๊ตฌ ์ด๋™์ด ๋ฐœ์ƒํ•œ ๋‚  ์ˆ˜ ์ฆ๊ฐ€
53+
54+
print(day)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
n = int(input())
5+
power = list(map(int, input().split()))
6+
7+
# ์ค€์›์ด๋ฅผ ์ œ์™ธํ•œ ๋‚˜๋จธ์ง€ ํ”Œ๋ ˆ์ด์–ด๋“ค์˜ ๊ณต๊ฒฉ๋ ฅ์„ ์ •๋ ฌํ•œ๋‹ค.
8+
others = sorted(power[1:])
9+
10+
# ์ค€์›์ด์˜ ์ดˆ๊ธฐ ๊ณต๊ฒฉ๋ ฅ
11+
junwon = power[0]
12+
13+
# ๋‚˜๋จธ์ง€ ํ”Œ๋ ˆ์ด์–ด๋“ค๊ณผ ๋น„๊ตํ•˜๋ฉด์„œ ์ฃผ์›์ด์˜ ์ตœ์ข… ์ƒ์กด ๊ฐ€๋Šฅ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จ
14+
for p in others:
15+
if junwon > p:
16+
junwon += p
17+
else:
18+
print("No")
19+
exit()
20+
21+
# ๋ชจ๋“  ํ”Œ๋ ˆ์ด์–ด๋ฅผ ์ด๊ฒผ๋‹ค๋ฉด "Yes"๋ฅผ ์ถœ๋ ฅ
22+
print("Yes")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sys
2+
import math
3+
input = sys.stdin.readline
4+
5+
n = int(input())
6+
7+
# ํ•™์ƒ ํ†ตํ™” ์‹œ๊ฐ„ ๊ณ„์‚ฐ ๋ฐ ์ €์žฅ
8+
call_log = {}
9+
for _ in range(n):
10+
time, name = map(str, input().split())
11+
hour, minute = map(int, time.split(":"))
12+
13+
if name in call_log:
14+
call_log[name] += minute + hour * 60
15+
else:
16+
call_log[name] = minute + hour * 60
17+
18+
# ํ†ตํ™” ์š”๊ธˆ ๊ณ„์‚ฐ
19+
charge = {}
20+
for k, v in call_log.items():
21+
if v <= 100:
22+
charge[k] = 10
23+
else:
24+
charge[k] = 10 + math.ceil((v - 100) / 50) * 3
25+
26+
for name, value in sorted(charge.items(), key=lambda x: (-x[1], x[0])):
27+
print(name, value)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sys
2+
input = sys.stdin.readline
3+
t, x, m = map(int, input().strip().split())
4+
5+
if m == 0:
6+
print(t * x)
7+
exit()
8+
9+
# ์ฒซ ๋ฒˆ์งธ ๋ชฌ์Šคํ„ฐ์˜ ๊ฑฐ๋ฆฌ์™€ ์†๋„ ์ž…๋ ฅ ๋ฐ›๊ธฐ
10+
d, s = map(int, sys.stdin.readline().strip().split())
11+
min_time = (d - 1) // s # ์ดˆ๊ธฐ ์ตœ์†Œ ๋„๋‹ฌ ์‹œ๊ฐ„ ์„ค์ •
12+
13+
# ๋‚˜๋จธ์ง€ ๋ชฌ์Šคํ„ฐ๋“ค์— ๋Œ€ํ•ด ์ตœ์†Œ ๋„๋‹ฌ ์‹œ๊ฐ„ ๊ณ„์‚ฐ
14+
for _ in range(m - 1):
15+
d, s = map(int, sys.stdin.readline().strip().split())
16+
time_to_reach = (d - 1) // s
17+
if min_time > time_to_reach:
18+
min_time = time_to_reach
19+
20+
if min_time == 0: # ์ตœ์†Œ ์‹œ๊ฐ„์ด 0์ด๋ผ๋ฉด ๊ธˆํ™”๋ฅผ ์ค์ง€ ๋ชปํ•จ
21+
print(0)
22+
elif t > min_time:
23+
# ์ด t ์‹œ๊ฐ„ ์ค‘ min_time ์‹œ๊ฐ„์„ ์‚ฌ์šฉํ•˜๊ณ  ๋‚จ์€ ์‹œ๊ฐ„์€ (t - min_time)
24+
# ์ด ๋‚จ์€ ์‹œ๊ฐ„์„ ์ ˆ๋ฐ˜์”ฉ ๋‚˜๋ˆ„์–ด ๊ธˆํ™”๋ฅผ ์ค๊ณ  ๊ธฐ๋‹ค๋ฆฌ๋Š” ๊ณผ์ •์„ ๋ฐ˜๋ณต
25+
print((min_time + ((t - min_time) // 2)) * x)
26+
else: # t < min_time
27+
print(t * x)

0 commit comments

Comments
ย (0)