結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-08-31 08:20:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,093 bytes
コンパイル時間 2,142 ms
コンパイル使用メモリ 200,800 KB
実行使用メモリ 4,824 KB
最終ジャッジ日時 2023-09-06 11:57:14
合計ジャッジ時間 4,733 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
4,632 KB
testcase_01 WA -
testcase_02 AC 173 ms
4,548 KB
testcase_03 AC 142 ms
4,824 KB
testcase_04 WA -
testcase_05 AC 3 ms
4,532 KB
testcase_06 AC 3 ms
4,660 KB
testcase_07 AC 3 ms
4,536 KB
testcase_08 AC 38 ms
4,816 KB
testcase_09 AC 2 ms
4,728 KB
testcase_10 AC 2 ms
4,528 KB
testcase_11 AC 2 ms
4,700 KB
testcase_12 AC 11 ms
4,600 KB
testcase_13 AC 2 ms
4,552 KB
testcase_14 AC 2 ms
4,600 KB
testcase_15 AC 3 ms
4,520 KB
testcase_16 AC 2 ms
4,536 KB
testcase_17 AC 2 ms
4,524 KB
testcase_18 AC 2 ms
4,624 KB
testcase_19 AC 2 ms
4,524 KB
testcase_20 AC 2 ms
4,528 KB
testcase_21 AC 2 ms
4,536 KB
testcase_22 AC 2 ms
4,536 KB
testcase_23 AC 2 ms
4,540 KB
testcase_24 AC 2 ms
4,524 KB
testcase_25 AC 2 ms
4,520 KB
testcase_26 AC 2 ms
4,540 KB
testcase_27 AC 2 ms
4,600 KB
testcase_28 AC 2 ms
4,600 KB
testcase_29 AC 2 ms
4,536 KB
testcase_30 AC 2 ms
4,524 KB
testcase_31 AC 2 ms
4,528 KB
testcase_32 AC 6 ms
4,604 KB
testcase_33 AC 3 ms
4,732 KB
testcase_34 AC 23 ms
4,600 KB
testcase_35 AC 173 ms
4,544 KB
testcase_36 AC 87 ms
4,564 KB
testcase_37 AC 168 ms
4,552 KB
testcase_38 AC 170 ms
4,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N;
int dp[301010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;

    rep(i, 0, 301010) dp[i] = inf;
    dp[0] = 0;

    rep(i, 1, N + 1) rep(x, 1, 10101) {
        if(i - x * x < 0) break;
        chmin(dp[i], dp[i - x * x] + x);
    }

    vector<int> ord;
    rep(x, 1, 10101) if(x * x <= N and x % 2 == 1) ord.push_back(x);
    rrep(x, 10101, 1) if(x * x <= N and x % 2 == 0) ord.push_back(x);

    string ans = "";
    int cu = N;
    int lst = 0;
    while(1 <= cu) {
        fore(x, ord) if(0 <= cu - x * x) if(dp[cu - x * x] + x == dp[cu]) {
            rep(i, 0, x) {
                if(0 < i) lst = 1 - lst;
                ans += char('0' + lst);
            }
            cu -= x*x;
            break;
        }
    }
    cout << ans << endl;
}





0