結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2016-05-18 10:04:57 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 782 bytes |
コンパイル時間 | 562 ms |
コンパイル使用メモリ | 64,372 KB |
実行使用メモリ | 814,108 KB |
最終ジャッジ日時 | 2024-10-06 05:27:07 |
合計ジャッジ時間 | 3,332 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--) { dp.push_back(dp[j] + weight[i]); } } if(std::find(dp.begin(), dp.end(), sum) != dp.end()) { std::cout << "possible" << std::endl; } else { std::cout << "impossible" << std::endl; } return 0; }