結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー pekempeypekempey
提出日時 2019-08-30 21:57:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,474 bytes
コンパイル時間 1,936 ms
コンパイル使用メモリ 177,020 KB
実行使用メモリ 5,676 KB
最終ジャッジ日時 2023-09-06 06:48:28
合計ジャッジ時間 4,885 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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<int> dp(N + 1, 1e9);
  vector<int> ep(N + 1, -1);
  dp[0] = 0;
  for (int i = 1; i * i <= N; i += 2) {
    for (int j = 0; j + i * i <= N; j++) {
      if (dp[j + i * i] > dp[j] + i) {
        dp[j + i * i] = dp[j] + i;
        ep[j + i * i] = i;
      }
    }
  }
  for (int i = 600; i >= 1; i--) {
    for (int j = 0; j + i * i <= N; j++) {
      if (dp[j + i * i] > dp[j] + i) {
        dp[j + i * i] = dp[j] + i;
        ep[j + i * i] = i;
      }
    }
  }
  vector<int> seq;
  int i = N;
  while (i != 0) {
    seq.push_back(ep[i]);
    i -= ep[i] * ep[i];
  }
  vector<int> odd;
  vector<int> even;
  for (int x : seq) {
    if (x % 2 == 0) even.push_back(x);
    else odd.push_back(x);
  }
  sort(odd.begin(), odd.begin());
  sort(even.rbegin(), even.rend());
  string ans;
  auto f = [&](int k) {
    char c = ans.empty() ? '0' : ans.back();
    rep(_, k) {
      ans += c;
      c ^= '0' ^ '1';
    };
  };
  for (int k : odd) f(k);
  // 0 n-1
  const int m = even.size();
  for (int i = 0; i < m; i++) {
    if (i % 2 == 0) {
      f(even[i / 2]);
    } else {
      f(even[m - 1 - i / 2]);
    }
  }
  cout << ans << endl;
}
0