結果
問題 | No.4 おもりと天秤 |
ユーザー |
|
提出日時 | 2022-10-23 21:02:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 669 bytes |
コンパイル時間 | 504 ms |
コンパイル使用メモリ | 64,000 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-02 11:09:32 |
合計ジャッジ時間 | 1,435 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <iostream> using namespace std; using LL = long long; bool dp[101][10001]; int main() { int N; cin >> N; dp[0][0] = true; int W, sum = 0; for (int i = 1; i <= N; i++) { cin >> W; for (int j = 0; j <= sum; j++) { if (dp[i - 1][j]) { dp[i][j] = true; dp[i][j + W] = true; } } sum += W; } bool ans = false; if (sum % 2 == 0) { for (int i = 1; i <= N; i++) { if (dp[i][sum / 2]) { ans = true; break; } } } cout << (ans ? "possible" : "impossible") << endl; }