結果
問題 |
No.873 バイナリ、ヤバいなり!w
|
ユーザー |
![]() |
提出日時 | 2024-04-15 11:45:25 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 550 ms / 2,000 ms |
コード長 | 801 bytes |
コンパイル時間 | 331 ms |
コンパイル使用メモリ | 81,936 KB |
実行使用メモリ | 78,640 KB |
最終ジャッジ日時 | 2024-10-05 07:09:20 |
合計ジャッジ時間 | 6,480 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
from collections import deque N=int(input()) inf=1<<30 dp=[inf]*(N+1) dp[0]=0 for i in range(1,N+1): for j in range(1,int(i**.5)+1): dp[i]=min(dp[i],dp[i-j*j]+j) lst=[[],[]] i=N while i: for j in range(1,int(i**.5)+1,2): if dp[i]==dp[i-j*j]+j: i-=j*j lst[j%2].append(j) break else: for j in range(2,int(i**.5)+1,2): if dp[i]==dp[i-j*j]+j: i-=j*j lst[j%2].append(j) break ans_lst=[] lst[0].sort() lst[1].sort() for x in lst[1]: for i in range(x): ans_lst.append(i%2) p=0 queue=deque(lst[0]) while queue: if p: x=queue.popleft() else: x=queue.pop() for i in range(x): ans_lst.append((i+p)%2) p^=1 print(*ans_lst,sep="")