結果

問題 No.1687 What the Heck?
ユーザー FromBooskaFromBooska
提出日時 2023-03-16 10:53:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 484 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 81,712 KB
実行使用メモリ 125,636 KB
最終ジャッジ日時 2023-10-18 12:57:05
合計ジャッジ時間 2,631 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,476 KB
testcase_01 AC 38 ms
53,476 KB
testcase_02 AC 38 ms
53,476 KB
testcase_03 AC 38 ms
53,476 KB
testcase_04 AC 38 ms
53,476 KB
testcase_05 AC 37 ms
53,476 KB
testcase_06 AC 38 ms
53,476 KB
testcase_07 AC 73 ms
87,384 KB
testcase_08 AC 85 ms
98,592 KB
testcase_09 AC 73 ms
87,372 KB
testcase_10 AC 63 ms
78,820 KB
testcase_11 AC 63 ms
78,904 KB
testcase_12 AC 137 ms
123,600 KB
testcase_13 AC 137 ms
123,600 KB
testcase_14 AC 137 ms
123,600 KB
testcase_15 AC 138 ms
123,600 KB
testcase_16 AC 136 ms
125,636 KB
testcase_17 AC 48 ms
65,344 KB
testcase_18 AC 135 ms
123,600 KB
testcase_19 AC 44 ms
60,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
P = list(map(int, input().split()))
dic = {}
for i in range(N):
    dic[P[i]] = i+1
#print(dic)
total = N*(N+1)//2

if N == 1:
    ans = 0
elif N == 2:
    if P[0] == 1:
        ans = 0
    else:
        ans = 1
else:
    # numだけ負ける、それ超はドローとする
    ans = 0
    draw = 0
    for num in range(N, 0, -1):
        second = dic[num]
        first = total - second - draw
        ans = max(ans, first-second)
        draw += second
print(ans)
0