結果
| 問題 | 
                            No.1150 シュークリームゲーム(Easy)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             gew1fw
                         | 
                    
| 提出日時 | 2025-06-12 19:39:46 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,787 bytes | 
| コンパイル時間 | 171 ms | 
| コンパイル使用メモリ | 82,752 KB | 
| 実行使用メモリ | 111,796 KB | 
| 最終ジャッジ日時 | 2025-06-12 19:39:55 | 
| 合計ジャッジ時間 | 5,281 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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()
            
            
            
        
            
gew1fw