結果
問題 | No.4 おもりと天秤 |
ユーザー |
|
提出日時 | 2017-06-24 01:44:38 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 25 ms / 5,000 ms |
コード長 | 933 bytes |
コンパイル時間 | 753 ms |
コンパイル使用メモリ | 75,260 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-26 10:20:19 |
合計ジャッジ時間 | 1,752 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <iostream> #include <cstdio> #include <vector> #include <list> #include <map> #include <queue> #include <set> #define rep(i, n) for(int (i)=0; (i)<(n); ++(i)) using namespace std; int main() { int n; cin >> n; int w[100]; map<int, bool> m; m[0] = true; int sum = 0; rep(i, n) { cin >> w[i]; sum += w[i]; } if(sum % 2 == 1) { cout << "impossible" << endl; return 0; } rep(i, n) { map<int, bool> mm; for(map<int, bool>::iterator itr = m.begin(); itr != m.end(); ++itr) { if(w[i] + itr->first == sum / 2) { cout << "possible" << endl; return 0; } mm[w[i] + itr->first] = true; } for(map<int, bool>::iterator itr = mm.begin(); itr != mm.end(); ++itr) { m[itr->first] = true; } } cout << "impossible" << endl; return 0; }