結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー 👑 emthrmemthrm
提出日時 2019-09-15 12:55:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 1,871 bytes
コンパイル時間 1,160 ms
コンパイル使用メモリ 117,980 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-09-02 07:12:18
合計ジャッジ時間 3,750 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
5,156 KB
testcase_01 AC 39 ms
4,384 KB
testcase_02 AC 163 ms
6,480 KB
testcase_03 AC 136 ms
5,964 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 35 ms
4,436 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 10 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 6 ms
4,380 KB
testcase_33 AC 3 ms
4,376 KB
testcase_34 AC 21 ms
4,380 KB
testcase_35 AC 175 ms
6,484 KB
testcase_36 AC 89 ms
5,488 KB
testcase_37 AC 174 ms
6,544 KB
testcase_38 AC 173 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
void solve(int len, char c, string &ans) {
  while (len--) {
    ans += c;
    if (c == '0') {
      c = '1';
    } else {
      c = '0';
    }
  }
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> dp(n + 1, INF), prev0(n + 1, -1), prev1(n + 1, -1);
  dp[0] = 0;
  FOR(i, 1, n + 1) {
    for (int j = 1; j * j <= i; ++j) {
      int score = dp[i - j * j] + j;
      if (score < dp[i]) {
        dp[i] = score;
        prev0[i] = prev1[i] = j;
      } else if (score == dp[i]) {
        if (prev0[i] % 2 == 0) prev0[i] = j;
        if (prev1[i] % 2 == 1) prev1[i] = j;
      }
    }
  }
  string ans = "0";
  int now = n;
  while (now > 0) {
    if (ans.back() == '0') {
      solve(prev0[now], '0', ans);
      now -= prev0[now] * prev0[now];
    } else {
      solve(prev1[now], '1', ans);
      now -= prev1[now] * prev1[now];
    }
  }
  ans.erase(ans.begin());
  cout << ans << '\n';
  return 0;
}
0