結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー NOSSNOSS
提出日時 2019-08-30 23:43:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,205 bytes
コンパイル時間 1,639 ms
コンパイル使用メモリ 177,032 KB
実行使用メモリ 7,784 KB
最終ジャッジ日時 2023-09-06 07:07:02
合計ジャッジ時間 4,050 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 35 ms
4,676 KB
testcase_02 AC 154 ms
7,652 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 29 ms
4,672 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 9 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 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,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 5 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 18 ms
4,380 KB
testcase_35 AC 161 ms
7,768 KB
testcase_36 AC 80 ms
5,984 KB
testcase_37 AC 166 ms
7,732 KB
testcase_38 AC 167 ms
7,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;

int main() {
    ll n;
    cin >> n;
    vector<ll> dp(n+1, IINF), pre(n+1);
    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;
                pre[i+j*j] = j;
            }
        }
    }
    vector<ll> len, ev, od;
    for(int i=n; i>0; i-=pre[i]*pre[i]){
        if(pre[i]%2){
            od.push_back(pre[i]);
        }
        else{
            ev.push_back(pre[i]);
        }
    }
    sort(od.begin(), od.end());
    sort(ev.rbegin(), ev.rend());
    for(auto l : od) len.push_back(l);
    for(int i=0,l=0,r=int(ev.size()-1);l<=r;i++){
        if(i%2){
            len.push_back(ev[r]);
            r--;
        }
        else{
            len.push_back(ev[l]);
            l++;
        }
    }
    string ans = "";
    int b = 0;
    for(auto l : len){
        for(int i=0;i<l;i++){
            ans.push_back(char('0'+(i+b)%2));
        }
        b ^= (l&1)^1;
    }
    cout << ans << endl;
    return 0;
}
0