結果

問題 No.1687 What the Heck?
ユーザー FromBooskaFromBooska
提出日時 2023-08-10 21:24:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 137,612 KB
最終ジャッジ日時 2023-08-10 21:24:47
合計ジャッジ時間 4,525 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,612 KB
testcase_01 AC 66 ms
71,440 KB
testcase_02 AC 65 ms
71,344 KB
testcase_03 AC 68 ms
71,484 KB
testcase_04 AC 66 ms
71,420 KB
testcase_05 AC 66 ms
71,368 KB
testcase_06 AC 67 ms
71,400 KB
testcase_07 AC 107 ms
103,596 KB
testcase_08 AC 128 ms
119,448 KB
testcase_09 AC 112 ms
103,880 KB
testcase_10 AC 97 ms
94,320 KB
testcase_11 AC 95 ms
94,328 KB
testcase_12 AC 176 ms
137,492 KB
testcase_13 AC 168 ms
137,432 KB
testcase_14 AC 177 ms
137,380 KB
testcase_15 AC 180 ms
137,432 KB
testcase_16 AC 179 ms
136,904 KB
testcase_17 AC 80 ms
77,780 KB
testcase_18 AC 177 ms
137,612 KB
testcase_19 AC 75 ms
76,680 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