結果

問題 No.884 Eat and Add
ユーザー mkawa2mkawa2
提出日時 2021-03-04 02:00:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 82 ms / 1,000 ms
コード長 1,560 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 16,316 KB
最終ジャッジ日時 2024-04-14 21:28:43
合計ジャッジ時間 1,494 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,752 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 64 ms
13,880 KB
testcase_04 AC 65 ms
13,888 KB
testcase_05 AC 60 ms
13,244 KB
testcase_06 AC 62 ms
13,248 KB
testcase_07 AC 42 ms
11,392 KB
testcase_08 AC 43 ms
11,520 KB
testcase_09 AC 82 ms
16,316 KB
testcase_10 AC 30 ms
10,752 KB
testcase_11 AC 31 ms
10,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def FI(): return float(sys.stdin.buffer.readline())
def MI(): return map(int, sys.stdin.buffer.readline().split())
def MF(): return map(float, sys.stdin.buffer.readline().split())
def MI1(): return map(int1, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
inf = 10**16
# md = 998244353
md = 10**9+7

def RLE(s):
    cc=[]
    ww=[]
    pc=s[0]
    w=0
    for c in s:
        if c==pc:w+=1
        else:
            cc.append(pc)
            ww.append(w)
            w=1
            pc=c
    cc.append(pc)
    ww.append(w)
    return cc,ww

s="000"+SI()
cc,ww=RLE(s)

ans=0
one=False
for w0,w1 in zip(ww[::2],ww[1::2]):
    if w0>2:
        if w1==1:
            ans+=1
            one=True
        else:
            ans+=2
            one=False
    elif not one and w1==1 and w0==1:
        ans+=1
        one=False
    elif w1==1:
        ans+=1
        one=True
    elif not one and w0==1 and w1>1:
        ans+=1
        one=False
    else:
        ans+=2
        one=False

print(ans)
0