結果
問題 |
No.1150 シュークリームゲーム(Easy)
|
ユーザー |
![]() |
提出日時 | 2025-05-14 12:47:24 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,336 bytes |
コンパイル時間 | 346 ms |
コンパイル使用メモリ | 82,588 KB |
実行使用メモリ | 97,508 KB |
最終ジャッジ日時 | 2025-05-14 12:48:29 |
合計ジャッジ時間 | 4,764 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 16 WA * 27 |
ソースコード
N = int(input()) s, t = map(int, input().split()) A = list(map(int, input().split())) used = [False] * (N + 1) # Using 1-based indexing used[s] = True used[t] = True x = A[s-1] y = A[t-1] def get_prev(pos): return (pos - 2) % N + 1 def get_next(pos): return pos % N + 1 # Initialize players' positions and candidates # Player 315: starts at s p315_L = p315_R = s p315_lc = get_prev(p315_L) p315_rc = get_next(p315_R) # Player 8128: starts at t p8128_L = p8128_R = t p8128_lc = get_prev(p8128_L) p8128_rc = get_next(p8128_R) turn = 0 # 0 for 315's turn, 1 for 8128's while True: current_player = turn % 2 moved = False if current_player == 0: # 315's turn candidates = [] if not used[p315_lc]: candidates.append((-A[p315_lc - 1], p315_lc, 'left')) # Negative for descending sort if not used[p315_rc]: candidates.append((-A[p315_rc - 1], p315_rc, 'right')) if candidates: candidates.sort() val_neg, pos, direction = candidates[0] val = -val_neg x += val used[pos] = True moved = True if direction == 'left': p315_L = pos p315_lc = get_prev(pos) else: p315_R = pos p315_rc = get_next(pos) else: # 8128's turn candidates = [] if not used[p8128_lc]: candidates.append((-A[p8128_lc - 1], p8128_lc, 'left')) if not used[p8128_rc]: candidates.append((-A[p8128_rc - 1], p8128_rc, 'right')) if candidates: candidates.sort() val_neg, pos, direction = candidates[0] val = -val_neg y += val used[pos] = True moved = True if direction == 'left': p8128_L = pos p8128_lc = get_prev(pos) else: p8128_R = pos p8128_rc = get_next(pos) # Check if any player can move next turn has_move = False # Check for 315 if (not used[p315_lc]) or (not used[p315_rc]): has_move = True # Check for 8128 if (not used[p8128_lc]) or (not used[p8128_rc]): has_move = True if not has_move: break turn += 1 print(x - y)