結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-08-31 08:53:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 2,744 bytes
コンパイル時間 2,034 ms
コンパイル使用メモリ 202,396 KB
実行使用メモリ 4,764 KB
最終ジャッジ日時 2023-09-02 07:11:11
合計ジャッジ時間 4,469 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
4,556 KB
testcase_01 AC 32 ms
4,532 KB
testcase_02 AC 137 ms
4,540 KB
testcase_03 AC 110 ms
4,620 KB
testcase_04 AC 3 ms
4,552 KB
testcase_05 AC 2 ms
4,736 KB
testcase_06 AC 3 ms
4,652 KB
testcase_07 AC 3 ms
4,524 KB
testcase_08 AC 28 ms
4,600 KB
testcase_09 AC 3 ms
4,652 KB
testcase_10 AC 2 ms
4,596 KB
testcase_11 AC 2 ms
4,544 KB
testcase_12 AC 9 ms
4,552 KB
testcase_13 AC 3 ms
4,532 KB
testcase_14 AC 2 ms
4,752 KB
testcase_15 AC 2 ms
4,516 KB
testcase_16 AC 2 ms
4,568 KB
testcase_17 AC 3 ms
4,548 KB
testcase_18 AC 3 ms
4,736 KB
testcase_19 AC 3 ms
4,536 KB
testcase_20 AC 3 ms
4,740 KB
testcase_21 AC 2 ms
4,532 KB
testcase_22 AC 3 ms
4,532 KB
testcase_23 AC 2 ms
4,568 KB
testcase_24 AC 2 ms
4,596 KB
testcase_25 AC 3 ms
4,608 KB
testcase_26 AC 2 ms
4,548 KB
testcase_27 AC 2 ms
4,652 KB
testcase_28 AC 3 ms
4,600 KB
testcase_29 AC 3 ms
4,736 KB
testcase_30 AC 2 ms
4,524 KB
testcase_31 AC 2 ms
4,524 KB
testcase_32 AC 5 ms
4,568 KB
testcase_33 AC 3 ms
4,764 KB
testcase_34 AC 18 ms
4,524 KB
testcase_35 AC 144 ms
4,548 KB
testcase_36 AC 72 ms
4,540 KB
testcase_37 AC 145 ms
4,744 KB
testcase_38 AC 144 ms
4,596 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> odd;
    rep(x, 1, 10101) if(x * x <= N and x % 2 == 1) odd.push_back(x);
    vector<int> even;
    rep(x, 1, 10101) if(x * x <= N and x % 2 == 0) even.push_back(x);
    int even_num = even.size();

    string ans = "";
    int cu = N;
    int lst = 0;
    while(1 <= cu) {
        int use = -1;
        fore(x, odd) if(0 <= cu - x * x) if(dp[cu - x * x] + x == dp[cu]) {
            use = x;
            break;
        }

        if(use < 0) {
            if(lst == 0) {
                rrep(i, even_num - 1, 0) {
                    int x = even[i];
                    if(0 <= cu - x * x) if(dp[cu - x * x] + x == dp[cu]) {
                        use = x;
                        break;
                    }
                }
            } else {
                fore(x, even) {
                    if(0 <= cu - x * x) if(dp[cu - x * x] + x == dp[cu]) {
                        use = x;
                        break;
                    }
                }
            }
        }

        rep(i, 0, use) {
            if(0 < i) lst = 1 - lst;
            ans += char('0' + lst);
        }
        cu -= use * use;
    }
    cout << ans << endl;
}





0