結果
| 問題 |
No.873 バイナリ、ヤバいなり!w
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2025-11-12 02:46:43 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 895 bytes |
| コンパイル時間 | 386 ms |
| コンパイル使用メモリ | 82,588 KB |
| 実行使用メモリ | 81,404 KB |
| 最終ジャッジ日時 | 2025-11-12 02:47:02 |
| 合計ジャッジ時間 | 12,368 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 WA * 1 |
ソースコード
import sys
input = sys.stdin.readline
from collections import deque
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()
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)))
titia