結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2017-06-29 17:40:54 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 609 bytes |
コンパイル時間 | 512 ms |
コンパイル使用メモリ | 62,936 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-04 16:45:55 |
合計ジャッジ時間 | 1,993 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 RE * 8 |
ソースコード
#include <iostream> #include <vector> #include <numeric> using namespace std; #define REP(i, N) for(int i=0;i<(N);++i) int main() { int n; cin >> n; vector<int> ws(n); REP(i, n) cin >> ws[i]; int sum = accumulate(ws.begin(), ws.end(), 0); if (sum % 2 == 1) { cout << "impossible" << endl; return 0; } int half = sum / 2; vector<bool> memo(half+1, false); memo[0] = true; for (int w : ws) { for (int i = half; i >= 0; --i) if(memo[i]) memo[i+w] = true; } if (memo[half]) cout << "possible" << endl; else cout << "impossible" << endl; }