結果

問題 No.873 バイナリ、ヤバいなり!w
コンテスト
ユーザー titia
提出日時 2025-11-12 02:30:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 791 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 82,844 KB
実行使用メモリ 80,836 KB
最終ジャッジ日時 2025-11-12 02:30:15
合計ジャッジ時間 10,659 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

N=int(input())

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

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
            FR[i+j*j]=i
            
ANS=[]
now=N

while now>0:
    to=FR[now]
    ANS.append(round((now-to)**(1/2)))
    now=to
        
E=[]
O=[]
for ans in ANS:
    if ans%2==0:
        E.append(ans)
    else:
        O.append(ans)

O.sort()
E.sort(reverse=True)

LANS=[]

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

for x in E:
    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