結果

問題 No.1505 Zero-Product Ranges
ユーザー tktk_snsn
提出日時 2021-05-14 23:30:54
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 410 bytes
コンパイル時間 686 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 19,736 KB
最終ジャッジ日時 2024-10-02 05:30:34
合計ジャッジ時間 7,126 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

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