結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2017-05-19 12:23:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,034 bytes |
コンパイル時間 | 891 ms |
コンパイル使用メモリ | 83,644 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-09-18 22:43:54 |
合計ジャッジ時間 | 2,781 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 WA * 3 |
ソースコード
#include <iostream> #include <vector> #include <numeric> #include <map> int N; std::vector<int> W; std::map<std::pair<int, int>, bool> mp; bool check(int ind, int t) { std::pair<int, int> p = std::make_pair(ind, t); if (mp.find(p) != mp.end()) { return mp[p]; } if (t == 0) { mp[p] = true; return true; } else if (t < 0) { mp[p] = false; return false; } for (int i = ind; i < N; i++) { if (check(i, t - W[i])) { mp[p] = true; return true; } } mp[p] = false; return false; } int main() { int sum; int target; std::cin >> N; W.resize(N); for (int i = 0; i < N; i++) { std::cin >> W[i]; } sum = std::accumulate(W.begin(), W.end(), 0); target = sum / 2; if (sum % 2 == 1) { std::cout << "impossible" << std::endl; } else if (check(0, target)) { std::cout << "possible" << std::endl; } else { std::cout << "impossible" << std::endl; } }