結果

問題 No.4 おもりと天秤
ユーザー DialBird
提出日時 2016-12-10 06:34:47
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 721 bytes
コンパイル時間 463 ms
コンパイル使用メモリ 60,880 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 10:04:51
合計ジャッジ時間 1,189 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <array>

using namespace std;

#define REP(i,first,last) for (int i=first;i<last;i++)
#define FOR(it,con) for (auto it=con.begin();it!=con.end();it++)

int N;
int half;
vector<int> w_list;
bool dp[10001] = {false};

int main(){
  cin >> N;
  dp[0] = true;
  int val;
  int total = 0;
  REP(i,0,N){
    cin >> val;
    w_list.push_back(val);
    total += val;
  }
  if (total & 1) {
    cout<<"impossible"<<endl;
  } else {
    half = total >> 1;
    for (auto w: w_list) {
      for (int i=10000;i>=0;i--) {
        if (dp[i] == true) dp[i + w] = true;
      }
    }
    if (dp[half]) {
      cout<<"possible"<<endl;
    } else {
      cout<<"impossible"<<endl;
    }
  }
}
0