結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-03-10 22:56:38 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 864 bytes |
| コンパイル時間 | 881 ms |
| コンパイル使用メモリ | 58,168 KB |
| 実行使用メモリ | 10,144 KB |
| 最終ジャッジ日時 | 2024-09-24 17:48:43 |
| 合計ジャッジ時間 | 7,345 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 TLE * 1 -- * 4 |
ソースコード
#include <iostream>
#include <string>
#include <numeric>
using namespace std;
bool isDevideInHalf(int* weights, int n, int index, int total_weight) {
if (total_weight == 0) return true;
if (index >= n) return false;
if (weights[index] <= total_weight) {
if (isDevideInHalf(weights, n, index + 1, total_weight - weights[index]))
return true;
return isDevideInHalf(weights, n, index + 1, total_weight);
}
return isDevideInHalf(weights, n, index + 1, total_weight);
}
int main() {
int n;
cin >> n;
int weights[100];
for (int i = 0; i < n; i++) {
cin >> weights[i];
}
bool is_possible = false;
int sum_weight = accumulate(weights, weights + n, 0);
if (sum_weight % 2 == 0) {
is_possible = isDevideInHalf(weights, n, 0, sum_weight / 2);
}
string answer = is_possible ? "possible" : "impossible";
cout << answer << endl;
return 0;
}