結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー pekempeypekempey
提出日時 2019-08-30 22:20:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 463 ms / 2,000 ms
コード長 1,444 bytes
コンパイル時間 1,794 ms
コンパイル使用メモリ 173,584 KB
実行使用メモリ 20,844 KB
最終ジャッジ日時 2023-09-02 07:07:40
合計ジャッジ時間 6,415 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 217 ms
13,212 KB
testcase_01 AC 120 ms
9,576 KB
testcase_02 AC 448 ms
20,024 KB
testcase_03 AC 367 ms
17,900 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 107 ms
8,804 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 32 ms
5,488 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,384 KB
testcase_32 AC 18 ms
4,432 KB
testcase_33 AC 5 ms
4,384 KB
testcase_34 AC 70 ms
7,332 KB
testcase_35 AC 463 ms
20,844 KB
testcase_36 AC 253 ms
14,328 KB
testcase_37 AC 461 ms
20,792 KB
testcase_38 AC 462 ms
20,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int N; cin >> N;
  vector<vector<int>> dp(N + 1);
  auto cmp = [&](vector<int> a, vector<int> b) {
    int s = 0;
    int t = 0;
    for (int x : a) s += x;
    for (int x : b) t += x;
    if (s != t) return s < t;
    int fst = 0;
    for (int i = 0; i < a.size(); i++) {
      if (a[i] > b[i]) return (fst ^ (b[i] & 1)) == 0;
      if (a[i] < b[i]) return (fst ^ (a[i] & 1)) == 1;
      fst ^= (a[i] & 1) ^ 1;
    }
    return false;
  };
  vector<int> ep(N + 1, 1e9);
  ep[0] = 0;
  for (int i = 1; i <= 600; i++) {
    for (int j = 0; j + i * i <= N; j++) {
      if (ep[j + i * i] > ep[j] + i) {
        ep[j + i * i] = ep[j] + i;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    vector<int> tmp(dp[i]);
    for (int j = 1; i + j * j <= N; j++) {
      if (ep[i + j * j] == ep[i] + j) {
        tmp.push_back(j);
        if (dp[i + j * j].empty() || cmp(tmp, dp[i + j * j])) {
          dp[i + j * j] = tmp;
        }
        tmp.pop_back();
      }
    }
  }
  string ans;
  char c = '0';
  for (int x : dp[N]) {
    rep(_, x) {
      ans += c;
      c ^= '0' ^ '1';
    }
    c ^= '0' ^ '1';
  }
  cout << ans << endl;
}
0