結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー lumc_lumc_
提出日時 2019-08-30 22:51:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,541 bytes
コンパイル時間 978 ms
コンパイル使用メモリ 102,048 KB
実行使用メモリ 5,772 KB
最終ジャッジ日時 2023-09-06 07:02:24
合計ジャッジ時間 14,084 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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) {
    if(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