結果

問題 No.4 おもりと天秤
ユーザー arrowsarrows
提出日時 2015-06-02 21:16:11
言語 C++11
(gcc 11.4.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 758 bytes
コンパイル時間 2,380 ms
コンパイル使用メモリ 144,756 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 17:20:17
合計ジャッジ時間 4,512 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define MAX_N 100
#define MAX_S 5000

int N,W[MAX_N],sum;

void solve(){
  bool dp[MAX_N][MAX_S+1];
  memset(dp,false,sizeof(dp));
  if(sum & 1){
    cout << "impossible" << endl;
    return;
  }
  dp[0][0] = true;
  for(int i = 0 ; i < N ; i++){
    for(int j = i ; j >= 0 ; j--){
      for(int k = MAX_S-W[i] ; k >= 0 ; k--){
        if(dp[j][k]){
          dp[j+1][k+W[i]] = true;
        }
      }
    }
  }
  bool found = false;
  for(int i = 1 ; i < N-1 ; i++){
    if(dp[i][sum/2]){
      found = true;
      break;
    }
  }
  cout << (found ? "possible" : "impossible") << endl;
}

int main(){
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    cin >> W[i];
    sum += W[i];
  }
  solve();
  return 0;
}
0