Skip to content

Instantly share code, notes, and snippets.

@maehrm
Created April 4, 2026 08:07
Show Gist options
  • Select an option

  • Save maehrm/f2d6fc7b8aaad1de8cc9e422b743df98 to your computer and use it in GitHub Desktop.

Select an option

Save maehrm/f2d6fc7b8aaad1de8cc9e422b743df98 to your computer and use it in GitHub Desktop.
import heapq
N = int(input())
slimes = {}
que = []
for _ in range(N):
s, c = map(int, input().split())
slimes[s] = c
heapq.heappush(que, s)
ans = 0
while que:
s = heapq.heappop(que)
c = slimes[s]
if c == 0:
continue
# 合体できない個体
ans += c % 2
# 合体してできる個体の数
nxt_c = c // 2
if nxt_c > 0:
nxt_s = 2 * s
if nxt_s not in slimes:
slimes[nxt_s] = 0
heapq.heappush(que, nxt_s)
slimes[nxt_s] += nxt_c
slimes[s] = 0
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment