結果
問題 | No.1150 シュークリームゲーム(Easy) |
ユーザー |
![]() |
提出日時 | 2025-06-12 14:41:13 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,901 bytes |
コンパイル時間 | 210 ms |
コンパイル使用メモリ | 82,084 KB |
実行使用メモリ | 100,224 KB |
最終ジャッジ日時 | 2025-06-12 14:41:27 |
合計ジャッジ時間 | 5,649 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 16 WA * 27 |
ソースコード
import heapq def main(): import sys input = sys.stdin.read().split() idx = 0 N = int(input[idx]) idx += 1 s = int(input[idx]) idx += 1 t = int(input[idx]) idx += 1 A = list(map(int, input[idx:idx + N])) idx += N # Convert to 1-based prev = [0] * (N + 1) next_ = [0] * (N + 1) for i in range(1, N + 1): prev[i] = i - 1 if i > 1 else N next_[i] = i + 1 if i < N else 1 taken = [False] * (N + 1) taken[s] = taken[t] = True X = A[s - 1] Y = A[t - 1] heap315 = [] heap8128 = [] # Initialize heaps for 315 for a in [prev[s], next_[s]]: if a != t and not taken[a]: heapq.heappush(heap315, (-A[a - 1], a)) # Initialize heaps for 8128 for a in [prev[t], next_[t]]: if a != s and not taken[a]: heapq.heappush(heap8128, (-A[a - 1], a)) turn = '315' while heap315 or heap8128: if turn == '315': if not heap315: turn = '8128' continue val, node = heapq.heappop(heap315) if taken[node]: continue X += (-val) taken[node] = True for neighbor in [prev[node], next_[node]]: if not taken[neighbor]: heapq.heappush(heap315, (-A[neighbor - 1], neighbor)) turn = '8128' else: if not heap8128: turn = '315' continue val, node = heapq.heappop(heap8128) if taken[node]: continue Y += (-val) taken[node] = True for neighbor in [prev[node], next_[node]]: if not taken[neighbor]: heapq.heappush(heap8128, (-A[neighbor - 1], neighbor)) turn = '315' print(X - Y) if __name__ == '__main__': main()