結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2017-10-16 18:37:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 792 bytes |
コンパイル時間 | 679 ms |
コンパイル使用メモリ | 81,752 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 10:23:49 |
合計ジャッジ時間 | 1,536 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <iostream> #include <queue> #include <vector> #include <cmath> #include <algorithm> #include <map> #include <numeric> using namespace std; using ll = long long; const ll INF = 1e9; const ll MOD = 1e9 + 7; int W[110]; bool dp[110][5010]; int main() { int N, sum = 0; cin >> N; for (int i = 0; i < N; i++) { cin >> W[i]; sum += W[i]; } if (sum % 2 > 0) { cout << "impossible" << endl; return 0; } int w = sum / 2; dp[0][0] = true; for (int i = 0; i < N; i++) { for (int v = 0; v <= w; v++) { if (dp[i][v]) { dp[i+1][v] = true; dp[i+1][v + W[i]] = true; } } } cout << (dp[N][w] ? "possible" : "impossible") << endl; return 0; }