結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー 👑 tatyamtatyam
提出日時 2019-07-11 02:07:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 1,004 bytes
コンパイル時間 2,806 ms
コンパイル使用メモリ 201,716 KB
実行使用メモリ 10,220 KB
最終ジャッジ日時 2023-09-02 07:06:33
合計ジャッジ時間 4,715 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
7,104 KB
testcase_01 AC 40 ms
5,644 KB
testcase_02 AC 172 ms
9,944 KB
testcase_03 AC 141 ms
8,780 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 35 ms
5,332 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 10 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 6 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 22 ms
4,896 KB
testcase_35 AC 179 ms
10,220 KB
testcase_36 AC 91 ms
7,628 KB
testcase_37 AC 182 ms
10,132 KB
testcase_38 AC 184 ms
10,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


ll priority(ll a){
    return a & 1 ? a : INF - a;
}
int main(){
    ll n;
    cin >> n;
    assert(1 <= n && n <= 300000);
    vector<ll> dp(n + 1, INF), min(n + 1, INF), max(n + 1, -INF);
    dp[0] = 0;
    for(ll i = 0; i < n; i++) for(ll j = 1; i + j * j <= n; j++){
        if(dp[i + j * j] > dp[i] + j){
            dp[i + j * j] = dp[i] + j;
            min[i + j * j] = j;
            max[i + j * j] = j;
        }
        else if(dp[i + j * j] == dp[i] + j){
            if(priority(min[i + j * j]) > priority(j)) min[i + j * j] = j;
            if(priority(max[i + j * j]) < priority(j)) max[i + j * j] = j;
        }
    }
    char c = '0';
    while(n){
        ll cnt;
        if(c == '0') cnt = min[n];
        else cnt = max[n];
        n -= cnt * cnt;
        for(ll i = 0; i < cnt; i++){
            cout << c;
            c ^= 1;
        }
        c ^= 1;
    }
    cout << endl;
}
0