結果

問題 No.4 おもりと天秤
ユーザー zezero
提出日時 2022-04-03 20:37:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 893 bytes
コンパイル時間 2,976 ms
コンパイル使用メモリ 172,320 KB
最終ジャッジ日時 2025-01-28 14:47:47
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <cmath>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)

int main(){
  int n;
  cin >> n;
  vector<vector<bool>> dp(n+1,vector<bool> (20001));
  int sum = 0;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
    sum += a[i];
  }
  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] = true;
        dp[i+1][j+a[i]] = true;
      }
    }
  }
  bool yes = false;
  for (int w = 0; w <= 1000;w++){
    if (dp[n][w] && w*2 == sum){
      yes = true;
      break;
    }
  }
  if (yes) cout << "possible" << endl;
  else cout << "impossible" << endl;
  return 0;
}
0