結果

問題 No.873 バイナリ、ヤバいなり!w
コンテスト
ユーザー titia
提出日時 2025-11-12 03:08:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,117 ms / 2,000 ms
コード長 1,265 bytes
コンパイル時間 214 ms
コンパイル使用メモリ 82,628 KB
実行使用メモリ 78,824 KB
最終ジャッジ日時 2025-11-12 03:09:02
合計ジャッジ時間 10,747 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

from collections import deque

N=int(input())

DP=[1<<30]*(N+1)
DP[0]=0

sq=round(N**(1/2))+2
for i in range(N+1):
    for j in range(1,sq):
        if i+j*j>N:
            break
        
        if DP[i+j*j]>=DP[i]+j:
            DP[i+j*j]=DP[i]+j
            
ANS=[]
now=N

while now>0:
    MIN=1<<30
    ind=-1
    for j in range(1,sq,2):
        if now-j*j<0:
            break
        if DP[now]==DP[now-j*j]+j:
            ind=j
            break

    if ind!=-1:
        ANS.append(ind)
        now-=ind*ind
        continue

    for j in range(sq//2*2,0,-2):
        
        if now-j*j<0:
            continue
        if DP[now]==DP[now-j*j]+j:
            ind=j
            break
    if ind!=-1:
        ANS.append(ind)
        now-=ind*ind


        
        
E=[]
O=[]
for ans in ANS:
    if ans%2==0:
        E.append(ans)
    else:
        O.append(ans)

O.sort()
E.sort()

LANS=[]

for x in O:
    S=[0]
    while len(S)<x:
        S.append(S[-1]^1)
    LANS+=S

E=deque(E)
c=0
while E:
    if c==0:
        x=E.pop()
    else:
        x=E.popleft()
    c^=1
    if LANS==[]:
        S=[0]
    else:
        S=[LANS[-1]]

    while len(S)<x:
        S.append(S[-1]^1)
    LANS+=S

print("".join(map(str,LANS)))
0