結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー E31415926E31415926
提出日時 2019-08-31 16:16:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,224 bytes
コンパイル時間 1,445 ms
コンパイル使用メモリ 166,756 KB
実行使用メモリ 10,508 KB
最終ジャッジ日時 2023-09-07 00:53:03
合計ジャッジ時間 6,444 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
9,716 KB
testcase_01 WA -
testcase_02 AC 227 ms
10,508 KB
testcase_03 AC 188 ms
10,384 KB
testcase_04 AC 3 ms
8,472 KB
testcase_05 AC 4 ms
8,400 KB
testcase_06 AC 3 ms
8,276 KB
testcase_07 AC 4 ms
8,280 KB
testcase_08 AC 50 ms
9,132 KB
testcase_09 AC 3 ms
8,352 KB
testcase_10 AC 3 ms
8,344 KB
testcase_11 AC 3 ms
8,460 KB
testcase_12 AC 15 ms
8,652 KB
testcase_13 AC 3 ms
8,288 KB
testcase_14 AC 3 ms
8,336 KB
testcase_15 AC 3 ms
8,328 KB
testcase_16 AC 3 ms
8,456 KB
testcase_17 AC 3 ms
8,328 KB
testcase_18 AC 3 ms
8,344 KB
testcase_19 AC 3 ms
8,416 KB
testcase_20 AC 3 ms
8,588 KB
testcase_21 AC 3 ms
8,328 KB
testcase_22 AC 3 ms
8,284 KB
testcase_23 AC 3 ms
8,288 KB
testcase_24 AC 3 ms
8,332 KB
testcase_25 AC 3 ms
8,288 KB
testcase_26 AC 3 ms
8,288 KB
testcase_27 AC 3 ms
8,332 KB
testcase_28 AC 3 ms
8,348 KB
testcase_29 AC 3 ms
8,596 KB
testcase_30 AC 3 ms
8,332 KB
testcase_31 AC 3 ms
8,360 KB
testcase_32 AC 9 ms
8,600 KB
testcase_33 AC 4 ms
8,336 KB
testcase_34 AC 33 ms
8,880 KB
testcase_35 AC 237 ms
10,368 KB
testcase_36 AC 125 ms
9,864 KB
testcase_37 AC 238 ms
10,400 KB
testcase_38 AC 237 ms
10,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int dp[300300];
int minv[300300];
int maxv[300300];

bool les(int a, int b) {
    if (a % 2 != b % 2) {
        return a % 2;
    }
    if (a % 2 == 1) {
        return a < b;
    }
    return a > b;
}

signed main() {
    int N;
    cin >> N;
    fill(dp, dp + 300300, INF);
    dp[0] = 0;
    minv[0] = 0, maxv[0] = 0;
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; i - j * j >= 0; ++j) {
            if (dp[i] > dp[i - j * j] + j) {
                dp[i] = dp[i - j * j] + j;
                minv[i] = j;
                maxv[i] = j;
            } else if (dp[i] == dp[i - j * j] + j) {
                minv[i] = les(minv[i], j) ? minv[i] : j;
                maxv[i] = les(maxv[i], j) ? j : maxv[j];
            }
        }
    }
    string ans;
    int s = 0;
    while (N) {
        int j = s == 0 ? minv[N] : maxv[N];
        rep(i, j) {
            ans.push_back(s + '0');
            s = 1 - s;
        }
        s = 1 - s;
        N -= j * j;
    }
    cout << ans << endl;
    return 0;
}
0