結果

問題 No.4 おもりと天秤
ユーザー twice_l
提出日時 2017-12-25 05:48:21
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 718 bytes
コンパイル時間 548 ms
コンパイル使用メモリ 62,236 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-17 19:20:22
合計ジャッジ時間 1,306 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
  int N, tmp, sum;
  vector<int> x;

  cin >> N;
  for(int i=0; i<N; ++i){
    cin >> tmp;
    x.push_back(tmp);
  }
  sum = accumulate(x.begin(), x.end(), 0);
  if(sum%2){
    cout << "impossible" << endl;
    return 0;
  }

  bool dp[N+10][sum+10];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = true;

  for(int i=0; i<N; i++){
    for(int j=0; j<=sum; j++){
      if(dp[i][j-x[i]]){
        if(j == sum/2){
          cout << "possible" << endl;
          return 0;
        }
        dp[i+1][j] = true;
      }
    }
  }
  cout << "impossible" << endl;
  return 0;
}
0