結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー face4face4
提出日時 2019-09-01 11:07:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,376 bytes
コンパイル時間 531 ms
コンパイル使用メモリ 69,820 KB
実行使用メモリ 6,800 KB
最終ジャッジ日時 2023-09-06 11:59:23
合計ジャッジ時間 4,010 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
5,144 KB
testcase_01 AC 68 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 59 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 17 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 9 ms
4,376 KB
testcase_33 AC 3 ms
4,376 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 151 ms
5,168 KB
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
const int INF = 1<<30;

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

const int siz = 3e5;

int main(){
    auto f = [](int val)->int{
        return val%2 == 1 ? val/2 : siz/2+(siz-val)/2;
    };
    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]) > f(j)) mi[i+j*j] = j;
                if(f(ma[i]) < 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