結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー lumc_lumc_
提出日時 2019-08-30 22:52:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 1,544 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 103,564 KB
実行使用メモリ 5,748 KB
最終ジャッジ日時 2023-09-02 07:09:45
合計ジャッジ時間 3,013 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
4,852 KB
testcase_01 AC 22 ms
4,380 KB
testcase_02 AC 93 ms
5,644 KB
testcase_03 AC 75 ms
5,476 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 20 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 14 ms
4,380 KB
testcase_35 AC 97 ms
5,732 KB
testcase_36 AC 51 ms
4,888 KB
testcase_37 AC 100 ms
5,748 KB
testcase_38 AC 99 ms
5,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

constexpr ll inf = 1e18;
ll dp[312345];

template <class T, class U> inline void smax(T &a, U b) { a = a > b ? a : b; }
template <class T, class U> inline void smin(T &a, U b) { a = a < b ? a : b; }


int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  ll n;
  cin >> n;

  for(int i = 1; i <= n; i++) dp[i] = inf;
  for(int i = 1; i * i <= n; i++) {
    for(int j = 0; j + i * i <= n; j++) {
      smin(dp[j+i*i], dp[j] + i);
    }
  }

  auto usable = [](ll n, ll x) -> bool {
    return n >= x * x and dp[n] == x + dp[n - x * x];
  };

  string ans;
  int last = 0;
  auto add = [&](ll x) -> void {
    for(int i = 0; i < x; i++) ans += '0' + last, last ^= 1;
    last ^= 1;
  };

  for(int i = 1; i*i <= n; i+=2) {
    while(usable(n, i)) {
      n -= i*i;
      add(i);
    }
  }

  ll l = 2;
  ll r = n/2*2;
  while(n) {
    if(last) {
      // 短く
      while(!usable(n, l)) l+=2;
      assert(n >= l * l);
      n -= l*l;
      add(l);
    } else {
      // 長く
      while(!usable(n, r)) r-=2;
      assert(n >= r * r);
      assert(r >= 2);
      n -= r*r;
      add(r);
    }
  }

  cout << ans << endl;

  return 0;
}
0