結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー beetbeet
提出日時 2019-08-30 22:10:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,591 bytes
コンパイル時間 2,409 ms
コンパイル使用メモリ 204,516 KB
実行使用メモリ 5,664 KB
最終ジャッジ日時 2023-09-06 06:57:20
合計ジャッジ時間 4,334 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 166 ms
5,512 KB
testcase_03 AC 136 ms
5,292 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 34 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 10 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 5 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 21 ms
4,376 KB
testcase_35 AC 175 ms
5,400 KB
testcase_36 AC 92 ms
4,568 KB
testcase_37 AC 171 ms
5,664 KB
testcase_38 AC 173 ms
5,352 KB
権限があれば一括ダウンロードができます

ソースコード

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