結果

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

ソースコード

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:
    #print(now)
    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

    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