結果

問題 No.1525 Meximum Sum
ユーザー ああいいああいい
提出日時 2022-02-26 13:02:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 446 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 109,120 KB
最終ジャッジ日時 2023-09-17 13:41:03
合計ジャッジ時間 6,004 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,592 KB
testcase_01 AC 75 ms
71,296 KB
testcase_02 AC 76 ms
71,428 KB
testcase_03 AC 75 ms
71,328 KB
testcase_04 AC 74 ms
71,404 KB
testcase_05 AC 75 ms
71,328 KB
testcase_06 AC 72 ms
71,252 KB
testcase_07 AC 76 ms
71,348 KB
testcase_08 AC 110 ms
97,848 KB
testcase_09 AC 117 ms
104,424 KB
testcase_10 AC 93 ms
83,408 KB
testcase_11 AC 99 ms
89,020 KB
testcase_12 AC 115 ms
101,392 KB
testcase_13 AC 124 ms
108,548 KB
testcase_14 AC 122 ms
108,556 KB
testcase_15 AC 124 ms
108,664 KB
testcase_16 AC 123 ms
108,544 KB
testcase_17 AC 122 ms
108,720 KB
testcase_18 AC 123 ms
108,476 KB
testcase_19 AC 123 ms
108,664 KB
testcase_20 AC 121 ms
108,760 KB
testcase_21 AC 128 ms
109,120 KB
testcase_22 AC 123 ms
108,732 KB
testcase_23 AC 119 ms
108,540 KB
testcase_24 AC 122 ms
108,560 KB
testcase_25 AC 125 ms
108,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int,input().split()))
d = [0] * N
for i in range(N):
    d[A[i]] = i
left = d[0]
right = d[0]
ans = 0
for i in range(1,N):
    pos = d[i]
    if left <= pos <= right:
        continue
    if pos > right:
        l = left + 1
        r = pos - right
        ans += i *l * r
        right = pos
    elif pos < left:
        l = left - pos
        r = N - right
        ans += i * l * r
        left = pos
print(ans+N)
0