結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー merom686merom686
提出日時 2023-12-06 21:49:35
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 1,119 bytes
コンパイル時間 2,951 ms
コンパイル使用メモリ 247,220 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-06 21:49:42
合計ジャッジ時間 6,847 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
6,676 KB
testcase_01 AC 33 ms
6,676 KB
testcase_02 AC 143 ms
6,676 KB
testcase_03 AC 116 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 28 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 8 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 1 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 5 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 17 ms
6,676 KB
testcase_35 AC 177 ms
6,676 KB
testcase_36 AC 75 ms
6,676 KB
testcase_37 AC 153 ms
6,676 KB
testcase_38 AC 152 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;

    vector<int> dp(n + 1);
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        int t = i;
        for (int j = 1; j * j <= i; j++) {
            t = min(t, dp[i - j * j] + j);
        }
        dp[i] = t;
    }

    int l = dp[n];
    string s(l, '0');
    int i0 = 0, u = n;

    for (int i = 1; i < l; i++) {
        int j = i - i0;
        int t = u - j * j;
        if (s[i - 1] == '0') {
            if (dp[u] == dp[t] + j) {
                u = t;
                i0 = i;
                s[i] = '0';
            } else {
                s[i] = '1';
            }
        } else {
            int f = 0;
            for (j++; j * j <= u; j++) {
                if (dp[u] == dp[u - j * j] + j) {
                    f = 1;
                    break;
                }
            }
            if (f == 0) {
                u = t;
                i0 = i;
                s[i] = '1';
            } else {
                s[i] = '0';
            }
        }
    }
    cout << s << endl;

    return 0;
}
0