結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー otoshigootoshigo
提出日時 2023-12-09 17:30:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,143 ms / 2,000 ms
コード長 1,835 bytes
コンパイル時間 954 ms
コンパイル使用メモリ 82,200 KB
実行使用メモリ 36,056 KB
最終ジャッジ日時 2023-12-09 17:30:15
合計ジャッジ時間 10,181 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 466 ms
22,096 KB
testcase_01 AC 253 ms
15,232 KB
testcase_02 AC 1,080 ms
35,024 KB
testcase_03 AC 843 ms
30,972 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 219 ms
14,208 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 57 ms
7,552 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 1 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 1 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 29 ms
6,676 KB
testcase_33 AC 7 ms
6,676 KB
testcase_34 AC 131 ms
11,008 KB
testcase_35 AC 1,110 ms
36,056 KB
testcase_36 AC 574 ms
24,180 KB
testcase_37 AC 1,143 ms
36,056 KB
testcase_38 AC 1,143 ms
36,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin>>N;
    vector dp(N+1,vector<int>(2,1<<30));
    vector to(N+1,vector<int>(2,-1));
    dp[N][0]=0;
    dp[N][1]=0;
    for(int x=N-1;x>=0;x--){
        for(int t=0;t<2;t++){
            if(t==0){
                for(int a=1;x+a*a<=N;a+=2){
                    if(chmin(dp[x][t],dp[x+a*a][t]+a)){
                        to[x][t]=a;
                    }
                }
                vector<int>v;
                for(int a=2;x+a*a<=N;a+=2)v.push_back(a);
                reverse(all(v));
                for(auto a:v){
                    if(chmin(dp[x][t],dp[x+a*a][1-t]+a)){
                        to[x][t]=a;
                    }
                }
            }else{
                for(int a=2;x+a*a<=N;a+=2){
                    if(chmin(dp[x][t],dp[x+a*a][1-t]+a)){
                        to[x][t]=a;
                    }
                }
                vector<int>v;
                for(int a=1;x+a*a<=N;a+=2)v.push_back(a);
                reverse(all(v));
                for(auto a:v){
                    if(chmin(dp[x][t],dp[x+a*a][t]+a)){
                        to[x][t]=a;
                    }
                }
            }
        }
    }
    int x=0,t=0;
    while(to[x][t]!=-1){
        int a=to[x][t];
        x+=a*a;
        if(a%2==0)t=1-t;
        for(int i=a-1;i>=0;i--){
            if(i%2==t)cout<<0;
            else cout<<1;
        }
    }
    cout<<"\n";
}
0