結果

問題 No.1505 Zero-Product Ranges
ユーザー tktk_snsntktk_snsn
提出日時 2021-05-14 23:30:54
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 410 bytes
コンパイル時間 487 ms
コンパイル使用メモリ 10,672 KB
実行使用メモリ 17,108 KB
最終ジャッジ日時 2023-07-25 11:06:48
合計ジャッジ時間 6,499 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,860 KB
testcase_01 AC 16 ms
7,752 KB
testcase_02 AC 16 ms
7,728 KB
testcase_03 AC 93 ms
11,992 KB
testcase_04 AC 94 ms
12,084 KB
testcase_05 AC 45 ms
9,208 KB
testcase_06 AC 45 ms
9,432 KB
testcase_07 AC 37 ms
8,952 KB
testcase_08 AC 41 ms
9,024 KB
testcase_09 AC 40 ms
9,064 KB
testcase_10 AC 40 ms
9,140 KB
testcase_11 AC 46 ms
9,444 KB
testcase_12 AC 36 ms
8,980 KB
testcase_13 AC 59 ms
10,432 KB
testcase_14 AC 54 ms
9,920 KB
testcase_15 AC 89 ms
11,380 KB
testcase_16 AC 139 ms
17,036 KB
testcase_17 AC 138 ms
17,108 KB
testcase_18 AC 138 ms
17,060 KB
testcase_19 AC 16 ms
7,820 KB
testcase_20 AC 16 ms
7,796 KB
testcase_21 AC 17 ms
7,816 KB
testcase_22 AC 136 ms
16,348 KB
testcase_23 AC 134 ms
16,348 KB
testcase_24 AC 129 ms
16,560 KB
testcase_25 AC 126 ms
16,312 KB
testcase_26 AC 132 ms
16,432 KB
testcase_27 AC 127 ms
16,464 KB
testcase_28 AC 128 ms
16,048 KB
testcase_29 AC 136 ms
16,700 KB
testcase_30 AC 135 ms
17,048 KB
testcase_31 AC 130 ms
15,872 KB
testcase_32 AC 76 ms
12,672 KB
testcase_33 AC 73 ms
12,204 KB
testcase_34 AC 80 ms
12,840 KB
testcase_35 AC 65 ms
11,536 KB
testcase_36 AC 66 ms
11,748 KB
testcase_37 AC 75 ms
12,492 KB
testcase_38 AC 71 ms
11,928 KB
testcase_39 AC 73 ms
12,012 KB
testcase_40 AC 75 ms
12,324 KB
testcase_41 AC 84 ms
13,116 KB
testcase_42 AC 23 ms
8,620 KB
testcase_43 AC 28 ms
8,956 KB
testcase_44 AC 26 ms
8,832 KB
testcase_45 AC 26 ms
8,768 KB
testcase_46 AC 22 ms
8,620 KB
testcase_47 AC 29 ms
8,864 KB
testcase_48 AC 24 ms
8,556 KB
testcase_49 AC 19 ms
8,284 KB
testcase_50 AC 24 ms
8,684 KB
testcase_51 AC 26 ms
8,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def RunLengthEncoding(S):
    res = []
    N = len(S)
    i = 0
    while i < N:
        cnt = 1
        while i < N - 1 and S[i] == S[i + 1]:
            cnt += 1
            i += 1
        res.append((S[i], cnt))
        i += 1
    return res


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

ans = N*(N+1)//2
for k, v in RunLengthEncoding(A):
    if k == 1:
        ans -= v * (v + 1) // 2
print(ans)
0