結果

問題 No.4 おもりと天秤
ユーザー arrowsarrows
提出日時 2015-06-02 13:28:28
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 647 bytes
コンパイル時間 1,391 ms
コンパイル使用メモリ 144,860 KB
実行使用メモリ 4,552 KB
最終ジャッジ日時 2023-09-20 18:44:12
合計ジャッジ時間 4,590 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define MAX_N 100
#define MAX_S 10000

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;
        }
      }
    }
  }
  cout << (dp[N/2][sum/2] ? "possible" : "impossible") << endl;
}

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