Created
April 4, 2026 08:07
-
-
Save maehrm/f2d6fc7b8aaad1de8cc9e422b743df98 to your computer and use it in GitHub Desktop.
D - Merge Slimes https://atcoder.jp/contests/abc323/tasks/abc323_d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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