結果

問題 No.4 おもりと天秤
ユーザー koba-e964
提出日時 2015-05-02 11:11:01
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,103 bytes
コンパイル時間 722 ms
コンパイル使用メモリ 88,524 KB
実行使用メモリ 7,500 KB
最終ジャッジ日時 2024-06-26 09:11:22
合計ジャッジ時間 1,537 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;

const int  N = 110;
const int W = 10100;
int n;
int a[N];
int dp[N][W];
int main(void){
  cin >> n;
  int tot = 0;
  REP(i, 0, n) {
    cin >> a[i];
    tot += a[i];
  }
  if (tot % 2 == 1) {
    cout << "impossible" << endl;
    return 0;
  }
  dp[0][0] = 1;
  REP(j, 1, W) {
    dp[0][j] = 0;
  }
  REP(i, 1, n + 1) {
    REP(j, 0, W) {
      dp[i][j] = dp[i-1][j];
      if (j >= a[i-1]) {
	dp[i][j] |= dp[i-1][j-a[i-1]];
      }
    }
  }
  cout << (dp[n][tot/2] ? "possible" : "impossible") << endl;

}
0