結果

問題 No.884 Eat and Add
ユーザー hedwig100hedwig100
提出日時 2020-04-16 15:59:28
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 87 ms / 1,000 ms
コード長 924 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 13,952 KB
最終ジャッジ日時 2024-10-01 19:23:11
合計ジャッジ時間 1,682 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 10 ** 20
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  heapq import heappop,heapify,heappush
from bisect import bisect_left

def main():
    n = list(input()) + ['0','0']

    ans = 0
    cnt_0 = 0
    flag = False
    cnt_1 = 0
    for i in range(len(n) - 2):
        if n[i] == '1':
            cnt_1 += 1
        if n[i] == '1' and n[i + 1] == '0' and n[i + 2] == '0':
            if cnt_1 > 1:
                flag = True
            if flag:
                ans += cnt_0 + 2
                cnt_0 = 0
                cnt_1 = 0
                flag = False
            else:
                ans += cnt_0 + 1
                cnt_0 = 0
                cnt_1 = 0
        if n[i] == '1' and n[i + 1] == '0' and n[i + 2] == '1':
            cnt_0 += 1
            if cnt_1 > 1:
                flag = True
            cnt_1 = 0

    print(ans)

if __name__ == '__main__':
    main()
0