結果
| 問題 |
No.873 バイナリ、ヤバいなり!w
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2019-08-30 22:06:57 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,591 bytes |
| コンパイル時間 | 1,894 ms |
| コンパイル使用メモリ | 199,132 KB |
| 最終ジャッジ日時 | 2025-01-07 15:55:43 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 WA * 24 |
ソースコード
#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=-1,l2=INF;
for(auto p:vp){
if(val<p.first) continue;
if(dp[val]!=dp[val-p.first]+p.second) continue;
if(p.first&1)
chmax(l1,p.second);
else
chmin(l2,p.second);
}
if(l1==-1){
print01(l2);
val-=l2*l2;
state=1;
}else{
print01(l1);
val-=l1*l1;
state=0;
}
}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!=INF){
print10(l2);
val-=l2*l2;
state^=1;
}else{
print10(l1);
val-=l1*l1;
state^=0;
}
}
}
cout<<endl;
return 0;
}
beet