結果
問題 |
No.1150 シュークリームゲーム(Easy)
|
ユーザー |
![]() |
提出日時 | 2025-06-12 19:21:30 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,475 bytes |
コンパイル時間 | 355 ms |
コンパイル使用メモリ | 81,860 KB |
実行使用メモリ | 92,236 KB |
最終ジャッジ日時 | 2025-06-12 19:22:04 |
合計ジャッジ時間 | 6,520 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 16 WA * 27 |
ソースコード
import heapq n = int(input()) s, t = map(int, input().split()) a = list(map(int, input().split())) s -= 1 # Convert to 0-based index t -= 1 used = [False] * n used[s] = True used[t] = True x = a[s] y = a[t] def get_neighbors(u): return (u - 1) % n, (u + 1) % n pq315 = [] pq8128 = [] # Initialize priority queues for both players for u in get_neighbors(s): if not used[u]: heapq.heappush(pq315, (-a[u], u)) for u in get_neighbors(t): if not used[u]: heapq.heappush(pq8128, (-a[u], u)) turn = 0 # 0 for 315's turn, 1 for 8128's turn remaining = n - 2 # Number of vertices left to capture while remaining > 0: if turn == 0: # 315's turn while pq315: val, u = heapq.heappop(pq315) val = -val if not used[u]: used[u] = True x += val remaining -= 1 for v in get_neighbors(u): if not used[v]: heapq.heappush(pq315, (-a[v], v)) break else: # 8128's turn while pq8128: val, u = heapq.heappop(pq8128) val = -val if not used[u]: used[u] = True y += val remaining -= 1 for v in get_neighbors(u): if not used[v]: heapq.heappush(pq8128, (-a[v], v)) break turn = 1 - turn print(x - y)