結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー kzyKTkzyKT
提出日時 2019-09-16 00:04:54
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,131 bytes
コンパイル時間 1,978 ms
コンパイル使用メモリ 157,388 KB
実行使用メモリ 8,580 KB
最終ジャッジ日時 2023-08-25 01:55:56
合計ジャッジ時間 3,197 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,844 KB
testcase_01 AC 5 ms
6,232 KB
testcase_02 WA -
testcase_03 AC 9 ms
7,916 KB
testcase_04 AC 2 ms
5,380 KB
testcase_05 AC 2 ms
5,420 KB
testcase_06 AC 2 ms
5,408 KB
testcase_07 AC 2 ms
5,436 KB
testcase_08 AC 5 ms
6,212 KB
testcase_09 AC 2 ms
5,396 KB
testcase_10 AC 2 ms
5,428 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 4 ms
5,756 KB
testcase_13 AC 2 ms
5,356 KB
testcase_14 AC 2 ms
5,360 KB
testcase_15 AC 2 ms
5,352 KB
testcase_16 AC 2 ms
5,372 KB
testcase_17 AC 2 ms
5,452 KB
testcase_18 AC 2 ms
5,452 KB
testcase_19 AC 2 ms
5,552 KB
testcase_20 AC 2 ms
5,572 KB
testcase_21 AC 2 ms
5,468 KB
testcase_22 AC 2 ms
5,436 KB
testcase_23 AC 2 ms
5,468 KB
testcase_24 AC 2 ms
5,436 KB
testcase_25 AC 2 ms
5,412 KB
testcase_26 AC 2 ms
5,396 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,568 KB
testcase_29 AC 2 ms
5,372 KB
testcase_30 AC 2 ms
5,408 KB
testcase_31 AC 2 ms
5,420 KB
testcase_32 AC 3 ms
5,560 KB
testcase_33 AC 3 ms
5,424 KB
testcase_34 AC 4 ms
5,916 KB
testcase_35 AC 11 ms
8,580 KB
testcase_36 AC 8 ms
6,928 KB
testcase_37 AC 11 ms
8,276 KB
testcase_38 AC 12 ms
8,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

ll dp[333333],p[333333];

void calc1(ll n) {
  fill(dp,dp+n+1,MAX);
  dp[0]=0;
  rep(i,n+1) {
    for(int j=1; i<1000; j+=2) {
      if(j*j+i>n) break;
      if(dp[j*j+i]>dp[i]+j) {
        dp[j*j+i]=dp[i]+j;
        p[j*j+i]=i;
      }
    }
    for(int j=2; i<1000; j+=2) {
      if(j*j+i>n) break;
      if(dp[j*j+i]>dp[i]+j) {
        dp[j*j+i]=dp[i]+j;
        p[j*j+i]=i;
      }
    }
  }
}

void calc2(ll n) {
  fill(dp,dp+n+1,MAX);
  dp[0]=0;
  rep(i,n+1) {
    for(int j=1; i<1000; j+=2) {
      if(j*j+i>n) break;
      if(dp[j*j+i]>dp[i]+j) {
        dp[j*j+i]=dp[i]+j;
        p[j*j+i]=i;
      }
    }
  }
  rep(i,n+1) {
    for(int j=2; i<1000; j+=2) {
      if(j*j+i>n) break;
      if(dp[j*j+i]>dp[i]+j) {
        dp[j*j+i]=dp[i]+j;
        p[j*j+i]=i;
      }
    }
  }
}

void calc3(ll n) {
  fill(dp,dp+n+1,MAX);
  dp[0]=0;
  rep(i,n+1) {
    for(int j=2; i<1000; j+=2) {
      if(j*j+i>n) break;
      if(dp[j*j+i]>dp[i]+j) {
        dp[j*j+i]=dp[i]+j;
        p[j*j+i]=i;
      }
    }
  }
  rep(i,n+1) {
    for(int j=1; i<1000; j+=2) {
      if(j*j+i>n) break;
      if(dp[j*j+i]>dp[i]+j) {
        dp[j*j+i]=dp[i]+j;
        p[j*j+i]=i;
      }
    }
  }
}

string solve(ll n,ll k) {
  if(k==1) calc1(n);
  else if(k==2) calc2(n);
  else  calc3(n);
  vector<ll> v;
  while(n) {
    ll k=n-p[n];
    v.pb(sqrt(k));
    n=p[n];
  }
  sort(all(v));
  string s="";
  rep(i,v.size()) {
    if(v[i]%2==0) continue;
    rep(j,v[i]) s+=(char)(j%2+'0');
  }
  deque<int> deq;
  rep(i,v.size()) {
    if(v[i]%2) continue;
    deq.push_back(v[i]);
  }
  int t=0;
  while(deq.size()) {
    int x;
    if(!t) {
      x=deq.back();
      deq.pop_back();
    } else {
      x=deq.front();
      deq.pop_front();
    }
    rep(j,x) s+=(char)((j+t)%2+'0');
    t^=1;
  }
  return s;
}

bool cmp(string s,string t) {
  if(s.size()!=t.size())return s.size()>t.size();
  rep(i,s.size())if(s[i]!=t[i])return s[i]>t[i];
  return 1;
}


void Main() {
  ll n;
  R n;
  string s=solve(n,1),t=solve(n,2),r=solve(n,3);
  if(cmp(s,t)) s=t;
  if(cmp(s,r)) s=r;
  pr(s);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
0