結果

問題 No.1525 Meximum Sum
ユーザー rlangevinrlangevin
提出日時 2023-02-12 01:41:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 568 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 86,840 KB
実行使用メモリ 109,048 KB
最終ジャッジ日時 2023-09-22 20:23:38
合計ジャッジ時間 6,816 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,240 KB
testcase_01 AC 75 ms
71,168 KB
testcase_02 AC 75 ms
71,216 KB
testcase_03 AC 75 ms
71,164 KB
testcase_04 AC 74 ms
71,108 KB
testcase_05 AC 76 ms
71,268 KB
testcase_06 AC 75 ms
71,136 KB
testcase_07 AC 73 ms
71,212 KB
testcase_08 AC 135 ms
97,612 KB
testcase_09 AC 115 ms
104,448 KB
testcase_10 AC 90 ms
83,328 KB
testcase_11 AC 96 ms
88,932 KB
testcase_12 AC 113 ms
101,300 KB
testcase_13 AC 123 ms
108,340 KB
testcase_14 AC 122 ms
108,416 KB
testcase_15 AC 121 ms
108,580 KB
testcase_16 AC 121 ms
108,584 KB
testcase_17 AC 126 ms
108,344 KB
testcase_18 AC 125 ms
108,344 KB
testcase_19 AC 124 ms
108,532 KB
testcase_20 AC 125 ms
108,340 KB
testcase_21 AC 128 ms
108,864 KB
testcase_22 AC 128 ms
108,348 KB
testcase_23 AC 123 ms
108,916 KB
testcase_24 AC 123 ms
109,048 KB
testcase_25 AC 127 ms
108,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int, input().split()))
ind = [0] * N
for i in range(N):
    ind[A[i]] = i
    
left = right = ind[0]
ans = 0
for i in range(1, N):
    now = ind[i]
    if left < now < right:
        pass
    elif now > right:
        ans += (now - right - 1) * i
        ans += left * i
        ans += i
        ans += (now - right - 1) * left * i
        right = now
    else:
        ans += (N - 1 - right) * i
        ans += (left - now - 1) * i
        ans += i
        ans += (N - 1 - right) * (left - now - 1) * i
        left = now

print(ans + N)
0