結果

問題 No.1505 Zero-Product Ranges
ユーザー tktk_snsntktk_snsn
提出日時 2021-05-14 23:30:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 410 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 19,736 KB
最終ジャッジ日時 2024-04-10 04:04:58
合計ジャッジ時間 6,106 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,752 KB
testcase_01 AC 28 ms
10,752 KB
testcase_02 AC 27 ms
10,752 KB
testcase_03 AC 103 ms
14,752 KB
testcase_04 AC 99 ms
14,672 KB
testcase_05 AC 54 ms
12,416 KB
testcase_06 AC 53 ms
12,112 KB
testcase_07 AC 48 ms
11,832 KB
testcase_08 AC 51 ms
11,776 KB
testcase_09 AC 50 ms
11,648 KB
testcase_10 AC 50 ms
12,032 KB
testcase_11 AC 55 ms
12,132 KB
testcase_12 AC 45 ms
11,520 KB
testcase_13 AC 67 ms
12,800 KB
testcase_14 AC 63 ms
12,648 KB
testcase_15 AC 96 ms
13,896 KB
testcase_16 AC 131 ms
19,608 KB
testcase_17 AC 130 ms
19,612 KB
testcase_18 AC 134 ms
19,736 KB
testcase_19 AC 27 ms
10,752 KB
testcase_20 AC 26 ms
10,624 KB
testcase_21 AC 26 ms
10,752 KB
testcase_22 AC 133 ms
19,236 KB
testcase_23 AC 131 ms
18,788 KB
testcase_24 AC 133 ms
19,004 KB
testcase_25 AC 131 ms
18,852 KB
testcase_26 AC 128 ms
19,008 KB
testcase_27 AC 131 ms
18,620 KB
testcase_28 AC 131 ms
18,716 KB
testcase_29 AC 133 ms
19,328 KB
testcase_30 AC 139 ms
18,996 KB
testcase_31 AC 133 ms
18,872 KB
testcase_32 AC 83 ms
15,264 KB
testcase_33 AC 76 ms
14,600 KB
testcase_34 AC 85 ms
15,296 KB
testcase_35 AC 69 ms
14,128 KB
testcase_36 AC 70 ms
14,256 KB
testcase_37 AC 80 ms
14,724 KB
testcase_38 AC 75 ms
14,580 KB
testcase_39 AC 76 ms
14,852 KB
testcase_40 AC 79 ms
14,976 KB
testcase_41 AC 91 ms
15,548 KB
testcase_42 AC 35 ms
11,136 KB
testcase_43 AC 38 ms
11,392 KB
testcase_44 AC 37 ms
11,264 KB
testcase_45 AC 37 ms
11,264 KB
testcase_46 AC 34 ms
11,136 KB
testcase_47 AC 44 ms
11,648 KB
testcase_48 AC 39 ms
11,264 KB
testcase_49 AC 30 ms
10,880 KB
testcase_50 AC 35 ms
11,392 KB
testcase_51 AC 37 ms
11,520 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