結果

問題 No.884 Eat and Add
ユーザー NoneNone
提出日時 2021-03-02 02:13:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 108 ms / 1,000 ms
コード長 2,082 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,592 KB
実行使用メモリ 109,764 KB
最終ジャッジ日時 2024-04-14 04:19:21
合計ジャッジ時間 1,765 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,272 KB
testcase_01 AC 39 ms
53,088 KB
testcase_02 AC 39 ms
52,652 KB
testcase_03 AC 104 ms
105,804 KB
testcase_04 AC 102 ms
104,696 KB
testcase_05 AC 102 ms
103,304 KB
testcase_06 AC 108 ms
104,048 KB
testcase_07 AC 65 ms
87,660 KB
testcase_08 AC 65 ms
87,928 KB
testcase_09 AC 91 ms
109,764 KB
testcase_10 AC 39 ms
53,948 KB
testcase_11 AC 39 ms
54,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Compress:
    def __init__(self,array):
        """ A=[(a,degeneracy),...] """
        S=[0]
        self.array=array[:]
        self.A=[]
        for a, cnt in array:
            S.append(S[-1]+cnt)
            self.A.append(a)
        self.S=S[1:]

    def __getitem__(self, i):
        j=bisect_left(self.S,i+1)
        return self.A[j]

    def sum(self, i):
        """ sum in [0,i) """
        j=bisect_left(self.S,i)
        res=0
        q=0
        for k in range(j):
            res+=self.A[k]*(self.S[k]-q)
            q=self.S[k]
        print(j, res)
        if j>0: res+=self.A[j]*(i-self.S[j-1])
        else: res+=self.A[j]*(i)
        return res

    def sort(self):
        S=[0]
        self.A=[]
        for a, cnt in sorted(self.array):
            S.append(S[-1]+cnt)
            self.A.append(a)
        self.S=S[1:]

    def __iter__(self):
        l=0
        for i in range(self.S[-1]):
            if i==self.S[l]:
                l+=1
            yield self.A[l]

    def __str__(self):
        return " ".join(list(map(str, self)))

def deg(A):
    """
    連続して続く文字を圧縮する(※Counterではない)
    [1,1,1,2,2,2,3] -> [(1,3),(2,3),(3,1)]
    """
    res=[]
    a0, cnt=A[0], 1
    for a in A[1:]+[None]:
        if a!=a0: res.append((a0,cnt)); cnt=1
        else: cnt+=1
        a0=a
    return res


def bit_rep(bit,N):
    return format(bit, "0" + str(N) + "b")
def bits_rep(bits,N):
    return [format(bit, "0" + str(N) + "b") for bit in bits]


###############################################################
import sys
from bisect import *
input = sys.stdin.readline

N=input().rstrip()
S=list(map(int,N))
data=deg(S)
res=0
i=0
A=[]
while i<len(data):
    if i>=len(data)-2 or data[i][0]==0 or data[i][1]<=1:
        A.append(data[i])
    else:
        j=i+1
        cnt=data[i][1]
        while j<len(data) and data[j][1]==1:
            res+=1
            cnt+=1+data[j+1][1]
            j+=2
        i=j-1
        A.append((1,cnt))
    i+=1

for a,cnt in A:
    if a==0:continue
    res+=min(2,cnt)
print(res)
0