結果

問題 No.1525 Meximum Sum
ユーザー roarisroaris
提出日時 2021-05-30 20:38:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 384 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 103,936 KB
最終ジャッジ日時 2024-04-26 07:54:09
合計ジャッジ時間 2,987 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,224 KB
testcase_01 AC 36 ms
52,224 KB
testcase_02 AC 36 ms
52,224 KB
testcase_03 AC 35 ms
52,352 KB
testcase_04 AC 35 ms
51,712 KB
testcase_05 AC 34 ms
51,712 KB
testcase_06 AC 34 ms
51,840 KB
testcase_07 AC 36 ms
52,224 KB
testcase_08 AC 71 ms
88,832 KB
testcase_09 AC 76 ms
97,536 KB
testcase_10 AC 56 ms
70,784 KB
testcase_11 AC 56 ms
78,080 KB
testcase_12 AC 73 ms
93,312 KB
testcase_13 AC 83 ms
102,912 KB
testcase_14 AC 82 ms
103,040 KB
testcase_15 AC 82 ms
102,912 KB
testcase_16 AC 81 ms
102,912 KB
testcase_17 AC 83 ms
102,528 KB
testcase_18 AC 82 ms
102,528 KB
testcase_19 AC 84 ms
102,912 KB
testcase_20 AC 82 ms
102,784 KB
testcase_21 AC 85 ms
103,936 KB
testcase_22 AC 84 ms
103,040 KB
testcase_23 AC 82 ms
103,808 KB
testcase_24 AC 85 ms
103,424 KB
testcase_25 AC 83 ms
103,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
idx = [-1]*N

for i in range(N):
    idx[A[i]] = i

l, r = idx[0], idx[0]
ans = 0

for i in range(1, N):
    if l<idx[i]<r:
        continue
    
    if idx[i]>r:
        ans += i*(l+1)*(idx[i]-r)
        r = idx[i]
    else:
        ans += i*(l-idx[i])*(N-r)
        l = idx[i]

print(ans+N)
0