結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-01-18 06:39:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 723 bytes |
| コンパイル時間 | 687 ms |
| コンパイル使用メモリ | 66,636 KB |
| 実行使用メモリ | 10,272 KB |
| 最終ジャッジ日時 | 2024-06-22 19:03:59 |
| 合計ジャッジ時間 | 7,357 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 WA * 1 TLE * 1 -- * 4 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <numeric>
#include <algorithm>
#include <utility>
using namespace std;
int n;
vector<int> w;
int half;
bool add(int sum, int idx) {
if (sum == half) {
return true;
} else if (sum > half) {
return false;
}
for (int i = idx + 1; i < n; i++) {
if(add(sum + w[idx], i)) {
return true;
}
}
return false;
}
int main() {
cin >> n;
w.assign(n, 0);
for (int i = 0; i < n; i++) {
cin >> w[i];
}
int total = accumulate(w.begin(), w.end(), 0);
sort(w.begin(), w.end(), greater<int>());
bool ret = false;
if (total % 2 == 0) {
half = total / 2;
ret = add(0, 0);
}
cout << (ret ? "possible" : "impossible") << endl;
return 0;
}