結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー face4face4
提出日時 2019-09-01 11:09:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 1,397 bytes
コンパイル時間 679 ms
コンパイル使用メモリ 69,812 KB
実行使用メモリ 6,504 KB
最終ジャッジ日時 2023-09-02 07:11:44
合計ジャッジ時間 3,477 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
5,128 KB
testcase_01 AC 44 ms
4,396 KB
testcase_02 AC 187 ms
6,504 KB
testcase_03 AC 153 ms
5,948 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 39 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 12 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 6 ms
4,380 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 25 ms
4,380 KB
testcase_35 AC 195 ms
6,444 KB
testcase_36 AC 100 ms
5,208 KB
testcase_37 AC 196 ms
6,416 KB
testcase_38 AC 196 ms
6,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 0にくっつけるなら奇数長で短い順->偶数長で長い順(偶数長の最初の01列は1始まりなので)
// 1にくっつけるなら↑の逆が良い(偶数長で短い順->奇数長で長い順)
// 復元の際に、現時点で文字列の末尾が0か1かに応じてappendする01列を変えるために、
// 上の順序付けにおいて最大最小をそれぞれ記録しておく

#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll LINF = 1ll<<60;

int main(){
    auto f = [](int val)->ll{
        return val%2 == 1 ? val : LINF-val;
    };
    int n;
    cin >> n;
    vector<int> dp(n+1, INF), mi(n+1, INF), ma(n+1, -INF);
    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;
                mi[i+j*j] = ma[i+j*j] = j;
            }else if(dp[i+j*j] == dp[i]+j){
                if(f(mi[i+j*j]) > f(j)) mi[i+j*j] = j;
                if(f(ma[i+j*j]) < f(j)) ma[i+j*j] = j;
            }
        }
    }
    int out = 0;
    while(n){
        int take;
        if(out == 0)    take = mi[n];
        else            take = ma[n];
        n -= take*take;
        while(take-- > 0){
            cout << out;
            out ^= 1;
        }
        out ^= 1;
    }
    cout << endl;
    return 0;
}
0