結果
問題 | No.873 バイナリ、ヤバいなり!w |
ユーザー |
![]() |
提出日時 | 2019-08-30 22:10:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,591 bytes |
コンパイル時間 | 1,868 ms |
コンパイル使用メモリ | 197,708 KB |
最終ジャッジ日時 | 2025-01-07 15:56:42 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 WA * 2 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} //INSERT ABOVE HERE void print01(Int len){ for(Int i=0;i<len;i++) cout<<(i&1); } void print10(Int len){ for(Int i=0;i<len;i++) cout<<(~i&1); } signed main(){ Int n; cin>>n; using P = pair<Int, Int>; vector<P> vp; for(Int i=1;i*i<=n;i++) vp.emplace_back(i*i,i); const Int INF = 1e15; vector<Int> dp(n+1,INF); dp[0]=0; for(auto p:vp) for(Int i=0;i+p.first<=n;i++) chmin(dp[i+p.first],dp[i]+p.second); Int val=n,state=0; while(val){ //cout<<l1<<" "<<l2<<endl; if(state==0){ Int l1=INF,l2=-1; for(auto p:vp){ if(val<p.first) continue; if(dp[val]!=dp[val-p.first]+p.second) continue; if(p.first&1) chmin(l1,p.second); else chmax(l2,p.second); } if(l1!=INF){ print01(l1); val-=l1*l1; state^=0; }else{ print01(l2); val-=l2*l2; state^=1; } }else{ Int l1=INF,l2=-1; for(auto p:vp){ if(val<p.first) continue; if(dp[val]!=dp[val-p.first]+p.second) continue; if(~p.first&1) chmax(l2,p.second); else chmin(l1,p.second); } if(l2!=-1){ print10(l2); val-=l2*l2; state^=1; }else{ print10(l1); val-=l1*l1; state^=0; } } } cout<<endl; return 0; }