結果
問題 | No.4 おもりと天秤 |
ユーザー |
|
提出日時 | 2015-04-21 16:12:30 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 524 bytes |
コンパイル時間 | 647 ms |
コンパイル使用メモリ | 60,452 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-26 09:10:32 |
合計ジャッジ時間 | 1,372 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { int N; cin >> N; int a; bool dp[10001] = {}, dp2[10001] = {}; int sum = 0; for (size_t i = 0; i < N; i++) { cin >> a; sum += a; for (size_t j = 0; j < 10001; j++) { if (dp[j]) { dp2[j + a] = 1; } } dp[a] = 1; for (size_t i = 0; i < 10001; i++) { dp[i] |= dp2[i]; } } if (!(sum%2)&&dp[sum / 2]) { cout << "possible" << endl; } else { cout << "impossible" << endl; } return 0; }