結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー 👑 tatyamtatyam
提出日時 2019-06-12 22:02:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,005 bytes
コンパイル時間 1,989 ms
コンパイル使用メモリ 200,620 KB
実行使用メモリ 5,492 KB
最終ジャッジ日時 2023-09-06 06:45:16
合計ジャッジ時間 4,435 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 35 ms
5,492 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 11 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 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 3 ms
4,380 KB
testcase_34 AC 22 ms
4,852 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
権限があれば一括ダウンロードができます

ソースコード

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 <= 100000);
    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