結果

問題 No.4 おもりと天秤
コンテスト
ユーザー Shopetan
提出日時 2017-07-21 17:19:19
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,641 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,550 ms
コンパイル使用メモリ 175,420 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-13 02:43:22
合計ジャッジ時間 1,606 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# include <bits/stdc++.h>

# define FOR(i,a,b) for (int i=(a);i<(b);i++)
# define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
# define REP(i, n) for (int i = 0; i < (int)(n); i++)
# define RREP(i,n) for (int i=(n)-1;i>=0;i--)

# define int(x) int x; scanf("%d",&x);
# define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
# define string(x) string x; cin >> x;

using namespace std;

namespace utils{
  template <typename T> void print(vector<vector<T>> mat) {
    REP (i, mat.size()) {
      REP (j, mat[0].size()) cout << mat[i][j] << ' ';
      cout << endl;
    }
  }

  template <typename T> void print(vector<T> v) {
    REP (i, v.size())
      if (i >= v.size()-1)
	cout << v[i];
      else
	cout << v[i] << ' ';
    
    cout << endl;
  }

  template <typename T> pair<T, T> shape(vector<vector<T>> mat) {
    int d1, d2;

    d1 = mat.size();
    if (d1 > 0) d2 = mat[0].size();
    else int d2 = 0;
    cout << "(" << d1 << ", " << d2 << ")" << endl;
    return make_pair(0, 0);
  }

  template <typename T> vector<vector<T>> empty(int n, int m) {
    vector<vector<T>> mat(n, vector<T>(m));
    return mat;
  }
}

bool dp[10000];

int main() {
  int(n);
  int w[100];
  int sum = 0;
  REP(i,n){
    cin >> w[i];
    sum += w[i];
  }

  //cout << (sum&1) << endl;
  if(sum&1){
    cout << "impossible" << endl;
    return 0;
  }
  int m = sum/2;
  
  dp[0] = true;
  REP(i,n){
    for(int j=m; j>=w[i];j--){
      //cout << j << " " << dp[j] << " " << j-w[i] << " " << dp[j-w[i]] << " " << w[i] << endl;
      dp[j] |= dp[j-w[i]];
    }
  }

  
  if(dp[m]) cout << "possible" << endl;
  else cout << "impossible" << endl;
}
0