結果
| 問題 | No.1687 What the Heck? | 
| コンテスト | |
| ユーザー |  gew1fw | 
| 提出日時 | 2025-06-12 16:51:39 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 542 bytes | 
| コンパイル時間 | 261 ms | 
| コンパイル使用メモリ | 82,140 KB | 
| 実行使用メモリ | 109,684 KB | 
| 最終ジャッジ日時 | 2025-06-12 16:52:34 | 
| 合計ジャッジ時間 | 2,614 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 1 WA * 17 | 
ソースコード
import sys
from collections import deque
def main():
    N = int(sys.stdin.readline())
    P = list(map(int, sys.stdin.readline().split()))
    
    i_list = list(range(1, N+1))[::-1]  # 轮次按从大到小排序
    Q = deque(range(1, N+1))
    
    total = 0
    
    for i in i_list:
        p = P[i-1]
        if Q[-1] > p:
            total += i
            Q.pop()
        elif Q[0] < p:
            total -= i
            Q.popleft()
        else:
            Q.popleft()
    
    print(total)
if __name__ == "__main__":
    main()
            
            
            
        