結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー treeonetreeone
提出日時 2019-08-30 23:09:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,810 bytes
コンパイル時間 2,164 ms
コンパイル使用メモリ 207,596 KB
実行使用メモリ 8,300 KB
最終ジャッジ日時 2023-09-06 07:05:10
合計ジャッジ時間 5,761 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 72 ms
6,276 KB
testcase_02 AC 295 ms
7,984 KB
testcase_03 WA -
testcase_04 AC 3 ms
5,416 KB
testcase_05 AC 2 ms
5,388 KB
testcase_06 AC 3 ms
5,408 KB
testcase_07 AC 2 ms
5,440 KB
testcase_08 AC 64 ms
6,192 KB
testcase_09 AC 2 ms
5,516 KB
testcase_10 AC 2 ms
5,416 KB
testcase_11 AC 2 ms
5,468 KB
testcase_12 AC 18 ms
5,704 KB
testcase_13 AC 2 ms
5,444 KB
testcase_14 AC 2 ms
5,392 KB
testcase_15 AC 2 ms
5,448 KB
testcase_16 AC 2 ms
5,392 KB
testcase_17 AC 2 ms
5,404 KB
testcase_18 AC 2 ms
5,420 KB
testcase_19 AC 2 ms
5,476 KB
testcase_20 AC 2 ms
5,400 KB
testcase_21 AC 3 ms
5,452 KB
testcase_22 AC 2 ms
5,440 KB
testcase_23 AC 2 ms
5,560 KB
testcase_24 AC 2 ms
5,400 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
5,468 KB
testcase_28 AC 2 ms
5,440 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
5,448 KB
testcase_32 AC 10 ms
5,632 KB
testcase_33 AC 3 ms
5,572 KB
testcase_34 AC 39 ms
6,032 KB
testcase_35 AC 304 ms
8,040 KB
testcase_36 AC 161 ms
6,900 KB
testcase_37 WA -
testcase_38 AC 306 ms
8,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int dp[300010], prv[300010];

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i = 0; i <= n; i++){
        dp[i] = i;
        prv[i] = 1;
    }
    for(int i = 2; i * i <= n; i++){
        for(int j = 0; j <= n - i * i; j++){
            // cout << i << ' ' << j << endl;
            if(dp[j + i * i] > dp[j] + i){
                dp[j + i * i] = dp[j] + i;
                prv[j + i * i] = i;
                // cout << "  " << dp[j + i * i] << endl;
            }else if(dp[j + i * i] == dp[j] + i){
                int tmp = prv[j + i * i];
                if(tmp % 2 == 0){
                    if(i % 2) prv[j + i * i] = i;
                    else prv[j + i * i] = i;
                }
            }
        }
    }
    vector<int> a;
    int now = n;
    while(now != 0){
        a.push_back(prv[now]);
        now = now - prv[now] * prv[now];
    }
    vector<int> odd, even;
    for(auto i : a){
        if(i % 2) odd.push_back(i);
        else even.push_back(i);
    }
    sort(odd.begin(), odd.end());
    sort(even.begin(), even.end());
    vector<int> tmp(even.size());
    rep(i, 0, even.size()){
        if(i % 2 == 0){
            tmp[i] = even[even.size() - 1 - i / 2];
        }else{
            tmp[i] = even[i / 2];
        }
    }
    even = tmp;
    a.clear();
    for(auto i : odd) a.push_back(i);
    for(auto i : even) a.push_back(i);
    string ans = "";
    int cnt = 0;
    for(auto i : a){
        rep(j, 0, i){
            ans += (cnt % 2 ? '1' : '0');
            cnt++;
        }
        cnt++;
    }
    cout << ans << endl;
}
0