結果

問題 No.884 Eat and Add
ユーザー tktk_snsntktk_snsn
提出日時 2021-02-11 19:29:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 104 ms / 1,000 ms
コード長 477 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 86,836 KB
実行使用メモリ 91,604 KB
最終ジャッジ日時 2023-09-25 09:12:57
合計ジャッジ時間 2,825 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,152 KB
testcase_01 AC 71 ms
71,028 KB
testcase_02 AC 79 ms
71,244 KB
testcase_03 AC 102 ms
83,768 KB
testcase_04 AC 104 ms
83,712 KB
testcase_05 AC 104 ms
82,736 KB
testcase_06 AC 100 ms
82,972 KB
testcase_07 AC 79 ms
75,500 KB
testcase_08 AC 78 ms
75,636 KB
testcase_09 AC 96 ms
91,604 KB
testcase_10 AC 73 ms
71,212 KB
testcase_11 AC 74 ms
71,192 KB
権限があれば一括ダウンロードができます

ソースコード

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(cnt)
        i += 1
    return res


S = input()
R = RunLengthEncoding(S)
if S[-1] == "0":
    R.pop()
R.reverse()


X = min(2, R[0])
Y = 0
for zero, one in zip(R[::2], R[1::2]):
    nX = min(X + min(2, one), Y + zero + 2)
    nY = min(X, Y + zero)
    X, Y = nX, nY
print(X)
0