結果

問題 No.4 おもりと天秤
ユーザー mkanmkan
提出日時 2017-03-26 19:27:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 856 bytes
コンパイル時間 479 ms
コンパイル使用メモリ 67,568 KB
実行使用メモリ 7,488 KB
最終ジャッジ日時 2023-09-08 17:21:58
合計ジャッジ時間 1,533 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 5 ms
7,332 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 6 ms
7,432 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 6 ms
7,276 KB
testcase_10 AC 6 ms
7,256 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 5 ms
7,248 KB
testcase_19 AC 6 ms
7,320 KB
testcase_20 AC 6 ms
7,276 KB
testcase_21 AC 6 ms
7,392 KB
testcase_22 AC 6 ms
7,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;
int sum=0;
int dp[101][10001];
int n,w[100];

void solve(){
  dp[0][0]=true;
  for(int i=0;i<n;i++){
    for(int j=0;j<10001;j++){
      if(dp[i][j]){
	dp[i+1][j+w[i]]=true;
	dp[i+1][j]=true;
      }
    }
  }
  if(debug){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	cout<<" "<<dp[i][j];
      }
      cout<<endl;
    }
  }
  if(dp[n-1][sum/2])cout<<"possible"<<endl;
  else cout<<"impossible"<<endl;
}

int main(){
  cin>>n;
    rep(i,0,n){
    cin>>w[i];
    sum+=w[i];
  }
    if(sum%2==1){
    cout<<"impossible"<<endl;
    return 0;
  }

  rep(i,0,n)rep(j,0,10001)dp[i][j]=false;
  solve();
  return 0;
}
0