結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー lam6er
提出日時 2025-03-26 15:57:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,679 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 90,288 KB
最終ジャッジ日時 2025-03-26 15:58:09
合計ジャッジ時間 7,798 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13 WA * 8 TLE * 1 -- * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s, t = map(int, input().split())
a = list(map(int, input().split()))

used = [False] * (n + 1)  # 1-based indexing
used[s] = True
used[t] = True

x = a[s-1]
y = a[t-1]

# 315's territory boundaries
l1 = r1 = s
# 8128's territory boundaries
l2 = r2 = t

turn = 0  # 0 for 315, 1 for 8128

while True:
    all_used = True
    for i in range(1, n+1):
        if not used[i]:
            all_used = False
            break
    if all_used:
        break
    
    if turn % 2 == 0:
        # 315's turn
        left = l1 - 1 if l1 > 1 else n
        right = r1 + 1 if r1 < n else 1
        candidates = []
        if not used[left]:
            candidates.append((a[left-1], left, 'left'))
        if not used[right]:
            candidates.append((a[right-1], right, 'right'))
        if candidates:
            candidates.sort(reverse=True, key=lambda x: x[0])
            val, pos, dir = candidates[0]
            x += val
            used[pos] = True
            if dir == 'left':
                l1 = pos
            else:
                r1 = pos
    else:
        # 8128's turn
        left = l2 - 1 if l2 > 1 else n
        right = r2 + 1 if r2 < n else 1
        candidates = []
        if not used[left]:
            candidates.append((a[left-1], left, 'left'))
        if not used[right]:
            candidates.append((a[right-1], right, 'right'))
        if candidates:
            candidates.sort(reverse=True, key=lambda x: x[0])
            val, pos, dir = candidates[0]
            y += val
            used[pos] = True
            if dir == 'left':
                l2 = pos
            else:
                r2 = pos
    
    turn += 1

print(x - y)
0