結果

問題 No.2608 Divide into two
ユーザー tanaka255tanaka255
提出日時 2024-01-19 21:30:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 1,000 ms
コード長 623 bytes
コンパイル時間 1,996 ms
コンパイル使用メモリ 208,376 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-01-19 21:30:27
合計ジャッジ時間 2,584 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
6,784 KB
testcase_01 AC 32 ms
6,784 KB
testcase_02 AC 33 ms
6,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<vector<bool> >dp(100+1,vector<bool>(2<<17,0));
  dp[0][0+1<<17]=1;
  for(int i=1;i<=100;++i){
    for(int j=0;j<(2<<17);++j){
      if(dp[i-1][j]){
        dp[i][j-i]=1;
        dp[i][j+i]=1;
      }
    }
  }
  int T;cin>>T;
  while(T--){
    int N;cin>>N;
    if(!dp[N][1<<17]){
      cout<<-1<<endl;
      continue;
    }
    int x=N,y=1<<17;
    vector<int>ans(N+1,0);
    while(0<x){
      if(dp[x-1][y-x]){
        ans[x]=1;
        y-=x;
      }else{
        y+=x;
      }
      --x;
    }
    for(int i=1;i<=N;++i)cout<<ans[i];
    cout<<'\n';
  }
}
0