結果

問題 No.1687 What the Heck?
ユーザー FromBooskaFromBooska
提出日時 2023-08-10 21:24:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 126,336 KB
最終ジャッジ日時 2024-04-28 14:31:28
合計ジャッジ時間 3,430 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
51,712 KB
testcase_01 AC 35 ms
51,584 KB
testcase_02 AC 37 ms
51,840 KB
testcase_03 AC 35 ms
51,584 KB
testcase_04 AC 36 ms
51,712 KB
testcase_05 AC 35 ms
51,968 KB
testcase_06 AC 36 ms
52,096 KB
testcase_07 AC 83 ms
98,432 KB
testcase_08 AC 100 ms
113,536 KB
testcase_09 AC 85 ms
98,432 KB
testcase_10 AC 71 ms
86,912 KB
testcase_11 AC 71 ms
87,424 KB
testcase_12 AC 158 ms
124,468 KB
testcase_13 AC 162 ms
124,228 KB
testcase_14 AC 154 ms
124,692 KB
testcase_15 AC 153 ms
124,436 KB
testcase_16 AC 154 ms
126,336 KB
testcase_17 AC 57 ms
68,352 KB
testcase_18 AC 158 ms
124,312 KB
testcase_19 AC 48 ms
61,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# たとえばN=5, P=[4, 2, 3, 5, 1]
# 上から何個引き分けるか、0個引き分ける場合は相手の5に1をぶつける
# 引き分けの次の数で負けて、あとは勝つ
# どれで負けるかで全探索しよう、それ以上の数は全引き分け、それ以下は全勝

N = int(input())
P = list(map(int, input().split()))

pos = {}
for i in range(N):
    pos[P[i]] = i+1

point_list = []
for num in range(1, N+1):
    point_list.append(pos[num])

#print(point_list)

cumu = [0]
temp = 0
for p in point_list:
    temp += p
    cumu.append(temp)
    
#print(cumu)

ans = 0
for lose in range(N, 0, -1):
    point = 0
    point += cumu[lose-1]
    point -= point_list[lose-1]
    #print('lose', lose, 'point', point)
    ans = max(ans, point)
print(ans)
0