結果

問題 No.921 ずんだアロー
ユーザー neterukun
提出日時 2019-11-08 21:28:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 824 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 96,128 KB
最終ジャッジ日時 2024-09-15 01:11:58
合計ジャッジ時間 2,647 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

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
            lsat = True
print(ans)
0