結果

問題 No.921 ずんだアロー
ユーザー neterukunneterukun
提出日時 2019-11-08 21:28:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 824 bytes
コンパイル時間 1,338 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 102,880 KB
最終ジャッジ日時 2023-10-13 03:31:02
合計ジャッジ時間 4,212 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,156 KB
testcase_01 AC 75 ms
71,352 KB
testcase_02 AC 76 ms
71,440 KB
testcase_03 WA -
testcase_04 AC 78 ms
71,112 KB
testcase_05 AC 76 ms
71,168 KB
testcase_06 AC 75 ms
71,124 KB
testcase_07 AC 75 ms
71,120 KB
testcase_08 AC 77 ms
71,392 KB
testcase_09 AC 76 ms
71,248 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 86 ms
78,584 KB
testcase_13 AC 100 ms
91,236 KB
testcase_14 AC 106 ms
93,312 KB
testcase_15 AC 92 ms
85,676 KB
testcase_16 AC 84 ms
76,520 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 116 ms
102,880 KB
testcase_24 AC 98 ms
92,212 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
            lsat = True
print(ans)
0