結果

問題 No.921 ずんだアロー
コンテスト
ユーザー neterukun
提出日時 2019-11-08 21:31:17
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 824 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 177 ms
コンパイル使用メモリ 85,632 KB
実行使用メモリ 96,512 KB
最終ジャッジ日時 2026-04-04 16:11:22
合計ジャッジ時間 1,834 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge5_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def run_length_compress(string):
    string = string + ["@"]
    n = len(string)

    begin = 0
    end = 1
    cnt = 1
    ans = []
    while True: 
        if end >= n:
            break
        if string[begin] == string[end]:
            end += 1
            cnt += 1
        else: 
            ans.append((cnt, string[begin]))
            begin = end
            end = begin + 1
            cnt = 1 
    
    return ans

n = int(input())
a = list(map(int, input().split()))

run_a = run_length_compress(a)
last = False
ans = 0
for num, _ in run_a:
    if last:
        if num == 1:
            last = False
        else:
            ans += num - 1
            last = True
    else:
        if num == 1:
            ans += 1
            last = True
        else:
            ans += num
            last = True
print(ans)
0