結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー pekempeypekempey
提出日時 2019-08-30 22:10:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,153 bytes
コンパイル時間 1,469 ms
コンパイル使用メモリ 173,412 KB
実行使用メモリ 21,364 KB
最終ジャッジ日時 2023-09-06 06:57:40
合計ジャッジ時間 8,159 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
  };
  for (int i = 0; i < N; i++) {
    for (int j = 1; i + j * j <= N; j++) {
      vector<int> tmp(dp[i]);
      tmp.push_back(j);
      if (dp[i + j * j].empty() || cmp(tmp, dp[i + j * j])) {
        dp[i + j * j] = tmp;
      }
    }
  }
  string ans;
  char c = '0';
  for (int x : dp[N]) {
    rep(_, x) {
      ans += c;
      c ^= '0' ^ '1';
    }
    c ^= '0' ^ '1';
  }
  cout << ans << endl;
}
0