結果

問題 No.1505 Zero-Product Ranges
ユーザー tktk_snsntktk_snsn
提出日時 2021-05-14 23:30:54
言語 Python3
(3.10.1 + numpy 1.22.3 + scipy 1.8.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 410 bytes
コンパイル時間 710 ms
使用メモリ 16,452 KB
最終ジャッジ日時 2022-11-25 22:57:36
合計ジャッジ時間 5,268 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 14 ms
7,644 KB
testcase_01 AC 14 ms
7,752 KB
testcase_02 AC 13 ms
7,572 KB
testcase_03 AC 79 ms
10,952 KB
testcase_04 AC 81 ms
11,112 KB
testcase_05 AC 39 ms
9,184 KB
testcase_06 AC 38 ms
9,096 KB
testcase_07 AC 31 ms
8,724 KB
testcase_08 AC 35 ms
8,968 KB
testcase_09 AC 35 ms
8,812 KB
testcase_10 AC 34 ms
8,816 KB
testcase_11 AC 40 ms
9,124 KB
testcase_12 AC 31 ms
8,796 KB
testcase_13 AC 51 ms
9,972 KB
testcase_14 AC 46 ms
9,736 KB
testcase_15 AC 78 ms
10,956 KB
testcase_16 AC 119 ms
16,400 KB
testcase_17 AC 118 ms
16,296 KB
testcase_18 AC 120 ms
16,452 KB
testcase_19 AC 15 ms
7,556 KB
testcase_20 AC 14 ms
7,640 KB
testcase_21 AC 13 ms
7,760 KB
testcase_22 AC 119 ms
16,144 KB
testcase_23 AC 111 ms
16,064 KB
testcase_24 AC 108 ms
15,640 KB
testcase_25 AC 106 ms
15,360 KB
testcase_26 AC 116 ms
15,604 KB
testcase_27 AC 114 ms
15,644 KB
testcase_28 AC 109 ms
15,588 KB
testcase_29 AC 117 ms
16,052 KB
testcase_30 AC 117 ms
16,396 KB
testcase_31 AC 112 ms
15,632 KB
testcase_32 AC 64 ms
12,012 KB
testcase_33 AC 62 ms
11,996 KB
testcase_34 AC 66 ms
12,412 KB
testcase_35 AC 53 ms
11,312 KB
testcase_36 AC 54 ms
11,132 KB
testcase_37 AC 62 ms
12,004 KB
testcase_38 AC 58 ms
11,456 KB
testcase_39 AC 60 ms
11,880 KB
testcase_40 AC 64 ms
12,124 KB
testcase_41 AC 69 ms
12,516 KB
testcase_42 AC 18 ms
8,312 KB
testcase_43 AC 22 ms
8,700 KB
testcase_44 AC 20 ms
8,524 KB
testcase_45 AC 21 ms
8,468 KB
testcase_46 AC 18 ms
8,172 KB
testcase_47 AC 23 ms
8,520 KB
testcase_48 AC 19 ms
8,324 KB
testcase_49 AC 16 ms
8,076 KB
testcase_50 AC 19 ms
8,328 KB
testcase_51 AC 21 ms
8,396 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