結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー betrue12betrue12
提出日時 2019-08-30 22:31:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 1,424 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 182,456 KB
実行使用メモリ 22,576 KB
最終ジャッジ日時 2023-09-02 07:09:42
合計ジャッジ時間 5,389 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
17,752 KB
testcase_01 AC 67 ms
15,268 KB
testcase_02 AC 241 ms
22,236 KB
testcase_03 AC 200 ms
20,860 KB
testcase_04 AC 6 ms
11,352 KB
testcase_05 AC 5 ms
11,276 KB
testcase_06 AC 6 ms
11,360 KB
testcase_07 AC 6 ms
11,376 KB
testcase_08 AC 60 ms
15,056 KB
testcase_09 AC 6 ms
11,180 KB
testcase_10 AC 6 ms
11,368 KB
testcase_11 AC 5 ms
11,076 KB
testcase_12 AC 22 ms
12,940 KB
testcase_13 AC 5 ms
11,176 KB
testcase_14 AC 6 ms
11,368 KB
testcase_15 AC 6 ms
11,364 KB
testcase_16 AC 6 ms
11,228 KB
testcase_17 AC 6 ms
11,112 KB
testcase_18 AC 6 ms
11,368 KB
testcase_19 AC 6 ms
11,276 KB
testcase_20 AC 6 ms
11,304 KB
testcase_21 AC 6 ms
11,364 KB
testcase_22 AC 5 ms
11,304 KB
testcase_23 AC 5 ms
11,304 KB
testcase_24 AC 6 ms
11,356 KB
testcase_25 AC 6 ms
11,236 KB
testcase_26 AC 5 ms
11,224 KB
testcase_27 AC 6 ms
11,192 KB
testcase_28 AC 6 ms
11,368 KB
testcase_29 AC 6 ms
11,356 KB
testcase_30 AC 5 ms
11,384 KB
testcase_31 AC 5 ms
11,064 KB
testcase_32 AC 15 ms
12,212 KB
testcase_33 AC 8 ms
11,652 KB
testcase_34 AC 42 ms
14,068 KB
testcase_35 AC 252 ms
22,576 KB
testcase_36 AC 136 ms
18,484 KB
testcase_37 AC 254 ms
22,576 KB
testcase_38 AC 254 ms
22,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<int> dp(300001, 1e9);
vector<vector<int>> prv(300001);

string Ans = "2";
void dfs(int N, vector<int>& v, int last){
    if(N == 0){
        deque<int> use[2];
        // for(int a : v) cerr << a << " ";
        // cerr << endl;
        for(int a : v) use[a%2].push_back(a);
        for(int k=0; k<2; k++) sort(use[k].begin(), use[k].end());
        string ans;
        bool onetop = false;
        for(int i : use[1]) for(int j=0; j<i; j++) ans.push_back('0' + j%2);
        while(use[0].size()){
            int num;
            if(!onetop){
                num = use[0].back(); use[0].pop_back();
            }else{
                num = use[0].front(); use[0].pop_front();
            }
            for(int j=0; j<num; j++) ans.push_back('0' + (j+onetop)%2);
            onetop = !onetop;
        }
        Ans = min(ans, Ans);
    }else{
        for(int a : prv[N]) if(last <= a){
            v.push_back(a);
            dfs(N-a*a, v, a);
            v.pop_back();
        }
    }
}

int main(){
    int N;
    cin >> N;
    dp[0] = 0;
    for(int i=0; i<N; i++) for(int j=1; i+j*j<=N; j++){
        if(dp[i+j*j] > dp[i] + j){
            dp[i+j*j] = dp[i] + j;
            prv[i+j*j] = {j};
        }else if(dp[i+j*j] >= dp[i] + j){
            prv[i+j*j].push_back(j);
        }
    }
    vector<int> v;
    dfs(N, v, 0);
    cout << Ans << endl;
    return 0;
}
0