結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2017-11-28 14:23:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 892 bytes |
コンパイル時間 | 479 ms |
コンパイル使用メモリ | 64,768 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 10:24:54 |
合計ジャッジ時間 | 1,237 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <iostream> using namespace std; #define fastcin {\ cin.tie(0);\ ios::sync_with_stdio(false);\ } #define scan(x) cin >> x #define print(x) cout << x << "\n" int main() { fastcin; int n, i, j; scan(n); int sum = 0, w[n]; for (i = 0; i < n; ++i) { scan(w[i]); sum += w[i]; } if ((sum & 0x01)) { } else { int half = sum/2; bool dp[n+1][half+1]; for (i = 0; i < n+1; ++i) for (j = 0; j < half+1; ++j) dp[i][j] = false; dp[0][0] = true; for (i = 0; i < n; ++i) { for (j = 0; j < half+1; ++j) { dp[i+1][j] |= dp[i][j]; if (j+w[i] <= half) dp[i+1][j+w[i]] |= dp[i][j]; } if (dp[n][half]) { print("possible"); return 0; } } } print("impossible"); return 0; }