結果

問題 No.2037 NAND Pyramid
ユーザー 👑 Kazun
提出日時 2022-08-12 23:32:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 731 bytes
コンパイル時間 486 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 111,208 KB
最終ジャッジ日時 2024-09-23 04:12:49
合計ジャッジ時間 5,770 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

def Run_Length_Encoding(S):
    """ランレングス圧縮

    S:文字列
    """
    if not S:
        return []

    R=[[S[0],1]]

    for i in range(1,len(S)):
        if R[-1][0]==S[i]:
            R[-1][1]+=1
        else:
            R.append([S[i],1])

    return R
#==================================================
def solve():
    N,K=map(int,input().split())
    S=list(map(int,input()))

    A=[0]*(N-1); B=[0]*(N-2)
    for i in range(N-1):
        A[i]=1-S[i]*S[i+1]
    for i in range(N-2):
        B[i]=1-A[i]*A[i+1]

    if len(B)%2==0:
        A,B=B,A

    if K%2==0:
        t=(len(A)-K)//2
        Ans=A[t:len(A)-t]
    else:
        t=(len(B)-K)//2
        Ans=B[t:len(B)-t]
    print(*Ans,sep="")

solve()
0