結果

問題 No.873 バイナリ、ヤバいなり!w
ユーザー otoshigootoshigo
提出日時 2023-12-09 16:36:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,703 bytes
コンパイル時間 825 ms
コンパイル使用メモリ 81,692 KB
実行使用メモリ 36,056 KB
最終ジャッジ日時 2023-12-09 16:36:25
合計ジャッジ時間 8,478 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
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 WA -
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 31 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 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 4 ms
6,676 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

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[0][0]=0;
    for(int x=0;x<N;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+a*a][t],dp[x][t]+a)){
                        to[x+a*a][t]=a;
                    }
                }
                for(int a=2;x+a*a<=N;a+=2){
                    if(chmin(dp[x+a*a][1-t],dp[x][t]+a)){
                        to[x+a*a][1-t]=a;
                    }
                }
            }else{
                for(int a=2;x+a*a<=N;a+=2){
                    if(chmin(dp[x+a*a][1-t],dp[x][t]+a)){
                        to[x+a*a][1-t]=a;
                    }
                }
                for(int a=1;x+a*a<=N;a+=2){
                    if(chmin(dp[x+a*a][t],dp[x][t]+a)){
                        to[x+a*a][t]=a;
                    }
                }
            }
        }
    }
    int x=N,t=0;
    if(dp[N][0]>dp[N][1])t=1;
    else t=0;
    string S="";
    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)S+='0';
            else S+='1';
        }
    }
    reverse(all(S));
    cout<<S<<"\n";
}
0