結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー CleyLCleyL
提出日時 2024-02-25 20:36:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,473 bytes
コンパイル時間 1,768 ms
コンパイル使用メモリ 143,100 KB
実行使用メモリ 27,560 KB
最終ジャッジ日時 2024-02-25 20:36:54
合計ジャッジ時間 9,253 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #


//yukicoder@cpp17

#include <iostream>
#include <iomanip>

#include <algorithm>

#include <cmath>
#include <cctype>
#include <climits>
#include <cassert>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>

#include <random>

#include <bitset>

#include <complex>

#include <utility>

#include <numeric>

#include <functional>


using namespace std;
using ll = long long;
using P = pair<ll,ll>;


const ll MOD = 998244353;
const ll MODx = 1000000007;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62LL)-1;
const double EPS = (1e-10);


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};


template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
 
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/

/* comment outed because can cause bugs
__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
*/

// 整数型を取得することを想定
template <typename T>
T CeilExactSqrt(int c, T x){
  T mn = 0;
  T mx = x;
  while(mx-mn > 1){
    T ce = (mn+mx)/2;
    T nw = 1;
    for(int i = 0; c > i; i++){
      if(x/ce < nw){
        mx = ce;
        break;
      }
      nw *= ce;
      if(i+1 == c && x == nw){
        mx = ce;
      }
    }
    if(mx != ce)mn = ce;
  }
  return mx;
}

template <typename T>
T FloorExactSqrt(int c, T x){
  T mn = 0;
  T mx = x;
  while(mx-mn > 1){
    T ce = (mn+mx)/2;
    T nw = 1;
    for(int i = 0; c > i; i++){
      if(x/ce < nw){
        mx = ce;
        break;
      }
      nw *= ce;
    }
    if(mx != ce)mn = ce;
  }
  return mn;
}

struct d{
  int n, i;
  bool operator<(const d a)const{
    if(n == a.n)return i < a.i;
    return n < a.n;
  }
};

map<d, int> X;

int b(int n, int i){
  if(n == 0 || i == 1){
    X[{n,i}] = n;
    return n;
  }
  else{
    int mn = n+1;
    int mnj = -1;
    for(int j = 0; n/(i*i) >= j; j++){
      int x = (b(n-j*(i*i), i-1)+j*i);
      if(x < mn){
        mn = x;
        mnj = j;
      }
    }
    X[{n,i}] = mnj;
    return mn;
  }
}

void zig(int x, char s){
  for(int i = 0; x > i; i++){
    cout << s;
    s = (s == '0' ? '1' : '0');
  }
}

int main(){
  long long n;cin>>n;
  if(n == 1){
    cout << "0" << endl;
    return 0;
  }
  b(n, FloorExactSqrt(2, n));
  int nwn = n;
  int i = FloorExactSqrt(2, n);
  vector<int> Z;
  while(X.find({nwn, i}) != X.end()){
    for(int j = 0; X[{nwn, i}] > j; j++){
      Z.push_back(i);
    }
    //cout << nwn << " " << i << " " << X[{nwn, i}] << endl;
    nwn = nwn-X[{nwn, i}]*(i*i);
    i--;
  }
  sort(Z.begin(), Z.end());
  char next = '0';
  deque<int> Zp;
  for(int j = 0; Z.size() > j; j++){
    if(Z[j]%2 == 1){
      zig(Z[j], next);
    }else{
      Zp.push_back(Z[j]);
    }
  }
  bool back = true;
  while(Zp.size()){
    if(back){
      auto z = Zp.back();Zp.pop_back();
      zig(z, '0');
    }else{
      auto z = Zp.front();Zp.pop_front();
      zig(z, '1');
    }
    back ^= 1;
  }
  cout << endl;

  return 0;
}
0