結果
問題 |
No.1150 シュークリームゲーム(Easy)
|
ユーザー |
![]() |
提出日時 | 2025-06-12 14:38:58 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,787 bytes |
コンパイル時間 | 349 ms |
コンパイル使用メモリ | 82,408 KB |
実行使用メモリ | 112,168 KB |
最終ジャッジ日時 | 2025-06-12 14:39:04 |
合計ジャッジ時間 | 5,510 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 13 WA * 7 TLE * 1 -- * 22 |
ソースコード
import heapq def main(): import sys input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) idx += 1 s = int(data[idx]) - 1 t = int(data[idx+1]) -1 idx +=2 A = list(map(int, data[idx:idx+N])) adj = [[] for _ in range(N)] for i in range(N): adj[i].append( (i-1) % N ) adj[i].append( (i+1) % N ) occupied = [False]*N occupied[s] = True occupied[t] = True X = A[s] Y = A[t] heap315 = [] heap8128 = [] for v in adj[s]: if v != t: heapq.heappush(heap315, (-A[v], v)) for v in adj[t]: if v != s: heapq.heappush(heap8128, (-A[v], v)) turn = 0 # 0 for 315, 1 for 8128 while True: if sum(occupied) == N: break if turn == 0: current_heap = heap315 while current_heap: a, u = heapq.heappop(current_heap) a = -a if not occupied[u]: X += a occupied[u] = True for v in adj[u]: if not occupied[v]: heapq.heappush(heap315, (-A[v], v)) break else: current_heap = heap8128 while current_heap: a, u = heapq.heappop(current_heap) a = -a if not occupied[u]: Y += a occupied[u] = True for v in adj[u]: if not occupied[v]: heapq.heappush(heap8128, (-A[v], v)) break turn = 1 - turn print(X - Y) if __name__ == "__main__": main()