結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-10 06:34:10 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 779 bytes |
| コンパイル時間 | 525 ms |
| コンパイル使用メモリ | 65,144 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-26 10:04:49 |
| 合計ジャッジ時間 | 1,294 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
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;
}
sort(w_list.begin(), w_list.end());
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;
}
}
}