結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,280 KB
testcase_01 AC 37 ms
53,280 KB
testcase_02 AC 37 ms
53,280 KB
testcase_03 AC 37 ms
53,280 KB
testcase_04 AC 37 ms
53,280 KB
testcase_05 AC 38 ms
53,280 KB
testcase_06 AC 37 ms
53,280 KB
testcase_07 AC 70 ms
87,200 KB
testcase_08 AC 82 ms
98,408 KB
testcase_09 AC 68 ms
87,188 KB
testcase_10 AC 59 ms
78,636 KB
testcase_11 AC 59 ms
78,720 KB
testcase_12 AC 130 ms
123,420 KB
testcase_13 AC 129 ms
123,420 KB
testcase_14 AC 129 ms
123,420 KB
testcase_15 AC 131 ms
123,420 KB
testcase_16 AC 128 ms
125,456 KB
testcase_17 AC 47 ms
65,160 KB
testcase_18 AC 129 ms
123,420 KB
testcase_19 AC 43 ms
59,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 簡単ではなかった
# 相手がNのときから1つずつ下がってみていく、辞書必要
# 相手の数字ごとに、それまでの相手の数字にはドローとして、その数字で負ける、あとは全勝とする

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