結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2021-08-10 21:45:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 782 bytes |
コンパイル時間 | 663 ms |
コンパイル使用メモリ | 74,544 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 23:25:49 |
合計ジャッジ時間 | 1,435 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> W(N); int sum = 0; for (int i = 0; i < N; i++) { cin >> W[i]; sum += W[i]; } if (sum % 2) { cout << "impossible" << endl; return 0; } vector<vector<bool>> dp(N + 1, vector<bool>(sum + 1, false)); dp[0][0] = true; for (int i = 0; i < N; i++) { for (int j = 0; j < sum; j++) { if (!dp[i][j]) { continue; } dp[i + 1][j] = true; dp[i + 1][j + W[i]] = true; } } if (dp[N][sum / 2]) { cout << "possible" << endl; } else { cout << "impossible" << endl; } }