結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー beet
提出日時 2019-08-30 22:01:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,425 bytes
コンパイル時間 1,884 ms
コンパイル使用メモリ 198,224 KB
最終ジャッジ日時 2025-01-07 15:53:34
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#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){
    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);
    }

    //cout<<l1<<" "<<l2<<endl;
    if(state==0){
      if(l1==-1){
        assert(l2!=INF);
        print01(l2);
        val-=l2*l2;
        state=1;
      }else{
        assert(l1>=0);
        print01(l1);
        val-=l1*l1;
        state=0;
      }
    }else{
      if(l2==INF){
        assert(l1>=0);
        print10(l1);
        val-=l1*l1;
        state=1;
      }else{
        assert(l2!=INF);
        print10(l2);
        val-=l2*l2;
        state=0;
      }
    }
  }
  cout<<endl;
  return 0;
}
0