結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-08-30 21:54:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,282 bytes
コンパイル時間 1,553 ms
コンパイル使用メモリ 111,656 KB
実行使用メモリ 25,692 KB
最終ジャッジ日時 2023-09-06 06:49:40
合計ジャッジ時間 68,038 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 1,550 ms
25,432 KB
testcase_05 AC 1,555 ms
25,552 KB
testcase_06 AC 1,594 ms
25,472 KB
testcase_07 AC 1,590 ms
25,552 KB
testcase_08 RE -
testcase_09 AC 1,566 ms
25,448 KB
testcase_10 AC 1,586 ms
25,408 KB
testcase_11 AC 1,542 ms
25,640 KB
testcase_12 AC 1,569 ms
25,480 KB
testcase_13 AC 1,581 ms
25,692 KB
testcase_14 AC 1,617 ms
25,476 KB
testcase_15 AC 1,610 ms
25,548 KB
testcase_16 AC 1,559 ms
25,560 KB
testcase_17 AC 1,590 ms
25,432 KB
testcase_18 AC 1,535 ms
25,396 KB
testcase_19 AC 1,632 ms
25,476 KB
testcase_20 AC 1,608 ms
25,636 KB
testcase_21 AC 1,545 ms
25,500 KB
testcase_22 AC 1,576 ms
25,632 KB
testcase_23 AC 1,553 ms
25,404 KB
testcase_24 AC 1,592 ms
25,476 KB
testcase_25 AC 1,587 ms
25,408 KB
testcase_26 AC 1,586 ms
25,464 KB
testcase_27 AC 1,568 ms
25,464 KB
testcase_28 AC 1,599 ms
25,472 KB
testcase_29 AC 1,564 ms
25,476 KB
testcase_30 AC 1,522 ms
25,484 KB
testcase_31 AC 1,542 ms
25,460 KB
testcase_32 AC 1,554 ms
25,428 KB
testcase_33 AC 1,545 ms
25,444 KB
testcase_34 AC 1,593 ms
25,444 KB
testcase_35 RE -
testcase_36 AC 1,589 ms
25,464 KB
testcase_37 RE -
testcase_38 AC 1,649 ms
25,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> void chmin(T &t, const T &f) { if (t > f) t = f; }
template <class T> void chmax(T &t, const T &f) { if (t < f) t = f; }

constexpr int MAX_L = 600;
constexpr int MAX_N = 300005;

bitset<MAX_N> dp[MAX_L];

int N;
int L;
char ans[MAX_L];

int main() {
  dp[0][0] = 1;
  for (int i = 0; i < MAX_L; ++i) {
    for (int j = 1; i + j < MAX_L; ++j) {
      dp[i + j] |= dp[i] << (j * j);
    }
  }
  /*
  bitset<MAX_N> sum;
  for (int i = 0; i < MAX_L; ++i) {
    sum |= dp[i];
  }
  assert(sum.all());
  //*/
  
  for (; ~scanf("%d", &N); ) {
    for (L = 0; !dp[L][N]; ++L) {}
cerr<<"L = "<<L<<endl;
    int now = 0;
    int last = 1, level = 0;
    for (int i = 0; i < L; ++i) {
      // check 0
      if (last == 0) {
        const int n = N - now - level * level;
        if (n >= 0 && dp[L - i][n]) {
          ans[i] = '0';
          now += level * level;
          last = 0;
          level = 1;
        } else {
          ans[i] = '1';
          last = 1;
          ++level;
        }
      } else {
        bool ok = false;
        for (int j = i + 1; j <= N; ++j) {
          const int n = N - now - (level + (j - i)) * (level + (j - i));
          ok = ok || (n >= 0 && dp[L - j][n]);
        }
        if (ok) {
          ans[i] = '0';
          last = 0;
          ++level;
        } else {
          ans[i] = '1';
          now += level * level;
          last = 1;
          level = 1;
        }
      }
    }
    ans[L] = '\0';
    puts(ans);
  }
  
  return 0;
}
0