結果
問題 |
No.1150 シュークリームゲーム(Easy)
|
ユーザー |
![]() |
提出日時 | 2025-04-09 20:56:15 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,865 bytes |
コンパイル時間 | 249 ms |
コンパイル使用メモリ | 82,044 KB |
実行使用メモリ | 92,268 KB |
最終ジャッジ日時 | 2025-04-09 20:58:10 |
合計ジャッジ時間 | 5,575 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 16 WA * 27 |
ソースコード
import heapq def main(): n = int(input()) s, t = map(int, input().split()) a = list(map(int, input().split())) used = [False] * (n + 1) # 1-based indexing # Mark initial positions as used used[s] = True used[t] = True x = a[s-1] y = a[t-1] heap315 = [] heap8128 = [] def get_neighbors(u): if u == 1: return [2, n] elif u == n: return [1, n-1] else: return [u-1, u+1] # Initialize heaps for both players for neighbor in get_neighbors(s): if not used[neighbor]: heapq.heappush(heap315, (-a[neighbor-1], neighbor)) for neighbor in get_neighbors(t): if not used[neighbor]: heapq.heappush(heap8128, (-a[neighbor-1], neighbor)) turn = 0 # 0 for 315's turn, 1 for 8128's turn while heap315 or heap8128: if turn == 0: # 315's turn while heap315: current_a, u = heapq.heappop(heap315) current_a = -current_a if not used[u]: x += current_a used[u] = True for v in get_neighbors(u): if not used[v]: heapq.heappush(heap315, (-a[v-1], v)) break turn = 1 else: # 8128's turn while heap8128: current_a, u = heapq.heappop(heap8128) current_a = -current_a if not used[u]: y += current_a used[u] = True for v in get_neighbors(u): if not used[v]: heapq.heappush(heap8128, (-a[v-1], v)) break turn = 0 print(x - y) if __name__ == "__main__": main()