結果

問題 No.921 ずんだアロー
ユーザー neterukunneterukun
提出日時 2019-11-08 21:31:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 824 bytes
コンパイル時間 725 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 102,932 KB
最終ジャッジ日時 2023-10-13 03:33:36
合計ジャッジ時間 3,998 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,412 KB
testcase_01 AC 72 ms
71,104 KB
testcase_02 AC 72 ms
71,272 KB
testcase_03 AC 72 ms
71,212 KB
testcase_04 AC 73 ms
71,416 KB
testcase_05 AC 72 ms
71,348 KB
testcase_06 AC 71 ms
71,276 KB
testcase_07 AC 71 ms
71,228 KB
testcase_08 AC 71 ms
71,268 KB
testcase_09 AC 72 ms
71,104 KB
testcase_10 AC 109 ms
98,520 KB
testcase_11 AC 111 ms
101,336 KB
testcase_12 AC 82 ms
78,596 KB
testcase_13 AC 98 ms
91,140 KB
testcase_14 AC 103 ms
93,520 KB
testcase_15 AC 90 ms
85,772 KB
testcase_16 AC 79 ms
76,612 KB
testcase_17 AC 107 ms
97,972 KB
testcase_18 AC 94 ms
92,272 KB
testcase_19 AC 95 ms
91,980 KB
testcase_20 AC 95 ms
92,316 KB
testcase_21 AC 95 ms
92,040 KB
testcase_22 AC 96 ms
92,188 KB
testcase_23 AC 112 ms
102,932 KB
testcase_24 AC 95 ms
92,316 KB
権限があれば一括ダウンロードができます

ソースコード

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