結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー Astral__Astral__
提出日時 2023-12-08 00:32:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 8,162 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 209,504 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-08 00:33:06
合計ジャッジ時間 7,172 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using PT = priority_queue<tuple<ll, ll, ll>, vector<tuple<ll, ll, ll>>, greater<tuple<ll, ll, ll>>>;
using PPQ = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;
using PQ = priority_queue<ll, vector<ll>, greater<ll>>;
using P =  pair<ll, ll>;
using vvvvl = vector<vector<vector<vector<ll>>>>;
using vvvi = vector<vector<vector<int>>>;
using vvvl = vector<vector<vector<ll>>>;
using vvvc = vector<vector<vector<char>>>;
using vvvd = vector<vector<vector<double>>>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvs = vector<vector<string>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<pair<ll, ll>>>;
using vvb = vector<vector<bool>>;
using vvd = vector<vector<double>>;
using vp = vector<pair<ll, ll>>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
#define vvvm  vector<vector<vector<mint>>>
#define vvm  vector<vector<mint>>
#define vm  vector<mint>
#define umap  unordered_map
#define uset  unordered_set
#define rrr(l, r) mt()%(r-l+1)+l
#define rep(i, s, f) for(long long i = s; i <= f; i++)
#define rep1(i, s, f) for(long long i = s; i <= f; i++)
#define per(i, s, f) for(long long i = s; i >= f; i--)
#define per1(i, s, f) for(long long i = s; i >= f; i--)
#define all0(x) (x).begin() ,(x).end()
#define all(x) (x).begin() + 1, (x).end()
#define ENDL '\n'

////////////////////////////////////////////////////////////////////////////////////////////////////////////
//これが本当の組み込み関数ってね(笑)

template <typename T>
T or_less(vector<T> &A, T x) { //x以下で最大要素の添字 前提: sort済み 存在しない: -1
  return distance(A.begin(), upper_bound(A.begin(), A.end(), x)-1);
}
template <typename T>
T under(vector<T> &A, T x) { //x未満の最大要素の添字 前提: sort済み 存在しない: -1
  return distance(A.begin(), lower_bound(A.begin(), A.end(), x)-1);
}
template <typename T>
T or_more(vector<T> &A, T x) { //x以上で最小要素の添字  前提: sort済み 存在しない: 配列のサイズ .   //distanceのA.beginは添字を出すために常にA.begin() NG: A.begin() + 1
  return distance(A.begin(), lower_bound(A.begin(), A.end(), x));
}
template <typename T>
T over(vector<T> &A, T x) { //xより大きい最小要素の添字前提: sort済み 存在しない: 配列のサイズ
  return distance(A.begin(), upper_bound(A.begin(), A.end(), x));
}
template <typename T>
vector<T> vec_shift(vector<T> A, ll step, ll dir, ll indexed) {//dir = 1 : 右シフト  dir = -1 : 左シフト
  ll N = A.size() - indexed;
  vector<T> res(N+1);
  rep(i, indexed, N) {
    ll idx = i - step * dir;
    if(idx < indexed) idx += N;
    if(idx > N) idx -= N;
    res.at(i) = A.at(idx);
  }
  return res;
}
template <typename T>
void UNIQUE(vector<T> &A, int indexed) {
    sort(A.begin() + indexed, A.end());
    A.erase(unique(A.begin() + indexed, A.end()), A.end());
}
template <typename T>
vector<T> RLE(vector<T> &A, int indexed) {
   vector<T> res(indexed, -INT_MAX);
   for(int i = indexed; i < int(A.size()); i++) {
     if(i == indexed) res.push_back(A[i]);
     else if(A[i-1] != A[i]) res.push_back(A[i]);
   }
   return res;
}
template <typename T>
void rev90(vector<vector<T>> &A, int indexed) {
  reverse(A.begin() + indexed, A.end());
  int n = A.size();
  rep(i, indexed, n-1) {
   rep(j, i+1, n-1) {
      swap(A.at(i).at(j), A.at(j).at(i));
    }
  }
}
int msb(long long a) {
    if(a == 0) return -1;
    return 64 - int(__builtin_clzll(a));
}
template<typename T = long long>
void chmin(T &a, T b) {
  a = min(a, b);
}
template<typename T = long long>
void chmax(T &a, T b) {
  a = max(a, b);
}
//////////////////////////////////////////////////////////////////////
//数学系
///////////////////////////////////////////////////////////////////////
ll round(ll x, ll i) {return ll(x + 5 * powl(10, i-1))/ll(powl(10, i)) * ll(powl(10, i));}
vp insu_bunkai(ll N) {
  vp res;
  for (ll i = 2; i * i <= N; i++) {
    ll cnt = 0;
    while(N % i == 0) {
      cnt++;
      N /= i;
    }
    if(cnt != 0) res.push_back(P(i, cnt));
  }
  if(N != 1) res.push_back(P(N, 1));
  return res;
}
ll extgcd (ll a, ll b,  ll &x, ll &y) {
  if(b == 0) { x = 1;y = 0;return a;}
  ll d = extgcd(b, a%b, y, x);
  y -= a/b * x;
  return d;
}
template <typename T>
T ceil(T a, T b) {
  assert(b != 0);
  if(a % b == 0) return a / b;
  if((a <= 0 && b < 0) || (a >= 0 && b > 0)) return a/b + 1;
  else return a / b;
}
template <typename T>
T floor(T a, T b) {
  assert(b != 0);
  if(a % b == 0) return a / b;
  if((a <= 0 && b < 0) || (a >= 0 && b > 0)) return a/b;
  else return a/b - 1;
}
ll modpow(ll x, ll y, ll mod) {
  if(x > mod) x %= mod;
  if(y == 0) return 1;
  ll res = modpow(x, y >> 1, mod);
  res = res * res % mod;
  if(y & 1) res *= x, res %= mod;
  return res;
}
ll sqrt_(ll a) {
    ll l = 0;
    ll r = 3037000499LL;
    while(l < r) {
        ll mid = (l + r + 1) / 2;
        if(mid * mid <= a) l = mid;
        else r = mid - 1;
    }
    return l;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//グローバル変数を置くところ(情報工学意識高め)
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
const ll int_max = 1001001001;
const ll ll_max = 1001001001001001001LL;
const double pi = 3.141592653589793;
vl dx{0, 1, 0, -1, 0, 1, 1, -1, -1};  // 座標平面において、(番兵) → ↓ ← ↑  ※ 右から時計回り 注 : グリッド or 座標で上下は反転する。
vl dy{0, 0, -1, 0, 1, 1, -1, -1, 1};
//const ll mod = 1000000007;
//const ll mod = 998244353;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve() {
  ll N;
  cin >> N;
  vl dp(N+1, ll_max);
  dp[0] = 0;
  dp[1] = 1;
  rep(i, 2, N) {
    for(ll j = 1; j*j <= N; j++) {
      chmin(dp[i], j + dp[N-j*j]);

    }
  }

  ll pre = 1;
  string ans = "";
  
  auto dfs = [&](auto dfs, ll now) -> void {
    if(now == 0) return;
    for(ll i = 1; i * i <= now; i++) {
      if(dp[now] == i + dp[now - i * i]) {
        rep(j, 1, i) {
          ans += '0' + (1 - pre);
        }
        pre = (1-pre);
        dfs(dfs, now-i*i);
        break;
      }
    }
  };

  dfs(dfs,N);

  cout << ans << endl;
 

    

}
//LISは連続とは限らない。
//mintでも0で割っては行けない(例: 関数の合成とかでやりがち assert落ちする)
//負の数を/2してはいけない(それはfloorでないから)
//DPを書く時は、定義を常に明確にする!定義を変えたいと思ったならば、定義が定まるまでは"必要な情報"を考える。
//尺取り法的な事をする時は、rは勿論"lもNを超え無いようにする"事!(違反するとエラーコード139が出たりする)
//無断で0を平方数にカウントする人もいる
//”部分文字列”と”連続部分文字列”は違うので確認すること
//一般のグラフと、有向辺かつその貼り方に制約がある(多くの場合:番号がで解放に伸びる)はだいぶ違うので確認すること
//座標を2で割った時の”切り捨て側(左側)”を求めるには 誤:(x / 2) マイナスの時!!! 正:floor<ll>(x, 2);
//stringでの数字の下から1桁目は 正:S.at(N-1)  誤:S.at(0)
//if(S.at(i) == 1) ← charなのに1...?
// modは取りましたか...?(´・ω・`)
//sortの比較関数は、 a == b ならば falseを返す必要がある(そうで無いとRE(発生しない場合もある))



int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(15);
    ll T = 1;
    //cin >> T;
    rep(i, 1, T) {
        solve();
    }
  return 0;
}
0