結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
hanorver
|
| 提出日時 | 2016-05-18 10:12:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 868 bytes |
| コンパイル時間 | 664 ms |
| コンパイル使用メモリ | 64,884 KB |
| 実行使用メモリ | 814,444 KB |
| 最終ジャッジ日時 | 2024-10-06 05:27:22 |
| 合計ジャッジ時間 | 3,573 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 MLE * 1 -- * 17 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
int main() {
int n;
std::cin >> n;
std::vector<int> weight(n);
for (int i = 0; i < n; i++) {
std::cin >> weight[i];
}
int sum = std::accumulate(weight.begin(), weight.end(), 0);
// 重さが奇数では天秤が平らになることはない
if (sum % 2 == 1) {
std::cout << "impossible" << std::endl;
return 0;
}
sum /= 2; // この重さを作れたら勝ち
std::vector<int> dp(1, 0);
for (int i = 0; i < weight.size(); i++) {
for (int j = dp.size() - 1; j >= 0; j--) {
if (dp[j] + weight[i] == sum) {
std::cout << "possible" << std::endl;
return 0;
}
if (dp[j] + weight[i] > sum) continue;
dp.push_back(dp[j] + weight[i]);
}
dp.erase(std::unique(dp.begin(), dp.end()), dp.end());
}
std::cout << "impossible" << std::endl;
return 0;
}
hanorver