Skip to content

Commit e736e3a

Browse files
authored
Merge pull request #121 from learntosurf/main
Learntosurf / 1์›” 2์ฃผ์ฐจ / 5๋ฌธ์ œ
2 parents 4aaaf76 + 1a86117 commit e736e3a

6 files changed

+127
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import sys
2+
input = sys.stdin.read
3+
4+
K = int(input())
5+
6+
stack = []
7+
8+
for _ in range(K) :
9+
N = int(input())
10+
if N == 0 :
11+
stack.pop()
12+
else :
13+
stack.append(N)
14+
15+
print(sum(stack))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sys
2+
input = sys.stdin.readline
3+
from collections import deque
4+
5+
N = int(input())
6+
cards = deque(range(1, N + 1)) # 1๋ถ€ํ„ฐ N๊นŒ์ง€์˜ ์ˆซ์ž๋ฅผ ๋ฑ์— ์ €์žฅ
7+
8+
while len(cards) > 1:
9+
cards.popleft() # ์ œ์ผ ์œ„์˜ ์นด๋“œ๋ฅผ ๋ฒ„๋ฆผ
10+
cards.append(cards.popleft()) # ๊ทธ๋‹ค์Œ ์นด๋“œ๋ฅผ ์•„๋ž˜๋กœ ์˜ฎ๊น€
11+
12+
print(cards[0]) # ๋งˆ์ง€๋ง‰์œผ๋กœ ๋‚จ์€ ์นด๋“œ ์ถœ๋ ฅ
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import sys
2+
input = sys.stdin.read
3+
4+
data = input().split()
5+
N, K = int(data[0]), int(data[1]) # ๋ฉ€ํ‹ฐํƒญ ๊ตฌ๋ฉ ์ˆ˜์™€ ์ „๊ธฐ ์šฉํ’ˆ ์‚ฌ์šฉ ํšŸ์ˆ˜
6+
sequence = list(map(int, data[2:])) # ์ „๊ธฐ ์šฉํ’ˆ ์‚ฌ์šฉ ์ˆœ์„œ
7+
8+
multitap = [] # ํ˜„์žฌ ๋ฉ€ํ‹ฐํƒญ ์ƒํƒœ
9+
unplug_count = 0 # ํ”Œ๋Ÿฌ๊ทธ๋ฅผ ๋ฝ‘๋Š” ํšŸ์ˆ˜
10+
11+
# ์ˆœ์ฐจ์ ์œผ๋กœ ์ „๊ธฐ์šฉํ’ˆ ์‚ฌ์šฉ
12+
for i in range(K):
13+
current = sequence[i]
14+
15+
# 1. ์ด๋ฏธ ๋ฉ€ํ‹ฐํƒญ์— ๊ฝ‚ํ˜€ ์žˆ๋Š” ๊ฒฝ์šฐ
16+
if current in multitap:
17+
continue # ์•„๋ฌด ์ž‘์—…๋„ ํ•˜์ง€ ์•Š๊ณ  ๋„˜์–ด๊ฐ
18+
19+
# 2. ๋ฉ€ํ‹ฐํƒญ์— ๋นˆ ์ž๋ฆฌ๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ
20+
if len(multitap) < N:
21+
multitap.append(current) # ์ƒˆ๋กœ์šด ์ „๊ธฐ์šฉํ’ˆ์„ ์ถ”๊ฐ€ํ•จ
22+
continue
23+
24+
# 3. ๋ฉ€ํ‹ฐํƒญ์ด ๊ฐ€๋“ ์ฐจ ์žˆ๋Š” ๊ฒฝ์šฐ: ๋ฝ‘์„ ์ „๊ธฐ ์šฉํ’ˆ ๊ฒฐ์ •
25+
farthest_idx = -1
26+
to_unplug = -1
27+
for plug in multitap:
28+
if plug not in sequence[i:]: # ์•ž์œผ๋กœ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ํ”Œ๋Ÿฌ๊ทธ
29+
to_unplug = plug
30+
break
31+
else:
32+
# ๊ฐ€์žฅ ๋‚˜์ค‘์— ์‚ฌ์šฉ๋˜๋Š” ํ”Œ๋Ÿฌ๊ทธ
33+
idx = sequence[i:].index(plug)
34+
if idx > farthest_idx:
35+
farthest_idx = idx
36+
to_unplug = plug
37+
38+
# ํ”Œ๋Ÿฌ๊ทธ ๊ต์ฒด
39+
multitap.remove(to_unplug)
40+
multitap.append(current)
41+
unplug_count += 1
42+
43+
print(unplug_count)
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+
N = int(input())
5+
fear = list(map(int, input().split()))
6+
fear.sort() # ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ
7+
8+
group = 0 # ๊ทธ๋ฃน ์ˆ˜
9+
member = 0 # ํ˜„์žฌ ๊ทธ๋ฃน์— ํฌํ•จ๋œ ๋ชจํ—˜๊ฐ€์˜ ์ˆ˜
10+
11+
for i in fear:
12+
# ํ˜„์žฌ ๊ทธ๋ฃน์— ์ธ์› ์ถ”๊ฐ€
13+
member += 1
14+
if member >= i: # ํ˜„์žฌ ๊ทธ๋ฃน์— ํฌํ•จ๋œ ๋ชจํ—˜๊ฐ€์˜ ์ˆ˜๊ฐ€ ๊ณตํฌ๋„ ์ด์ƒ์ด๋ฉด ๊ทธ๋ฃน ๊ฒฐ์„ฑ
15+
group += 1
16+
member = 0 # ํ˜„์žฌ ๊ทธ๋ฃน์— ํฌํ•จ๋œ ์ธ์› ์ดˆ๊ธฐํ™”
17+
18+
print(group)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
S = list(map(int, input().rstrip()))
5+
6+
num = S[0] # ์ฒซ๋ฒˆ์งธ ์ •์ˆ˜๋ฅผ ์ดˆ๊ธฐ ๊ฒฐ๊ณผ๊ฐ’์œผ๋กœ ์ง€์ •
7+
8+
for i in range(1, len(S)):
9+
# ํ•ด๋‹น ์ •์ˆ˜๊ฐ€ 1 ์ดํ•˜์ด๊ฑฐ๋‚˜, ์ดˆ๊ธฐ ๊ฒฐ๊ณผ๊ฐ’์ด 1 ์ดํ•˜์ผ ๊ฒฝ์šฐ
10+
if S[i] <= 1 or num <= 1:
11+
num += S[i] # ๋ง์…ˆ
12+
# ํ•ด๋‹น ์ •์ˆ˜๊ฐ€ 2 ์ด์ƒ์„ ๊ฒฝ์šฐ
13+
else:
14+
num *= S[i] # ๊ณฑ์…ˆ
15+
16+
print(num)
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+
S = list(input().rstrip())
5+
6+
count_0 = 0 # 0์ด ์—ฐ์†๋˜๋Š” ๋ถ€๋ถ„์˜ ๊ฐœ์ˆ˜
7+
count_1 = 0 # 1์ด ์—ฐ์†๋˜๋Š” ๋ถ€๋ถ„์˜ ๊ฐœ์ˆ˜
8+
9+
# ์—ฐ์†๋œ ์ •์ˆ˜๊ฐ€ ๋‹ค๋ฅธ ์ •์ˆ˜๋กœ ๋ฐ”๋€” ๋•Œ, ์—ฐ์†๋œ ๋ถ€๋ถ„์˜ ๊ฐœ์ˆ˜ ์ถ”๊ฐ€
10+
for i in range(1, len(S)):
11+
if S[i] != S[i-1]: # ์ด์ „ ์ˆ˜์™€ ๋‹ค๋ฅธ ๊ฒฝ์šฐ
12+
if S[i-1] == '0': # ์ด์ „ ์ˆ˜๊ฐ€ 0์ธ ๊ฒฝ์šฐ
13+
count_0 += 1
14+
else: # ์ด์ „ ์ˆ˜๊ฐ€ 1์ธ ๊ฒฝ์šฐ
15+
count_1 += 1
16+
17+
# ๋ฃจํ”„์—์„œ ์ฒ˜๋ฆฌํ•˜์ง€ ๋ชปํ•œ ๋งˆ์ง€๋ง‰ ์ˆซ์ž ์ฒ˜๋ฆฌ
18+
if S[-1] == '0': # ๋ฌธ์ž์—ด์˜ ๋งˆ์ง€๋ง‰ ๋ฌธ์ž๊ฐ€ 0์ด๋ฉด
19+
count_0 += 1
20+
else: # ๋ฌธ์ž์—ด์˜ ๋งˆ์ง€๋ง‰ ๋ฌธ์ž๊ฐ€ 1์ด๋ฉด
21+
count_1 += 1
22+
23+
print(min(count_0, count_1))

0 commit comments

Comments
ย (0)