結果

問題 No.884 Eat and Add
ユーザー NoneNone
提出日時 2021-03-02 02:01:18
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 1,861 bytes
コンパイル時間 1,099 ms
コンパイル使用メモリ 87,300 KB
実行使用メモリ 105,512 KB
最終ジャッジ日時 2023-07-26 14:18:02
合計ジャッジ時間 2,518 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,352 KB
testcase_01 AC 75 ms
71,352 KB
testcase_02 AC 77 ms
71,244 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 105 ms
95,972 KB
testcase_08 AC 104 ms
95,916 KB
testcase_09 AC 130 ms
102,448 KB
testcase_10 AC 77 ms
71,080 KB
testcase_11 AC 76 ms
71,148 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
for i in range(len(data)):
    a,cnt=data[i]
    if a==0:continue
    if i!=0 and data[i-1][1]==1:
        res+=min(1,cnt)
    else:
        res+=min(2,cnt)
print(res)
0