結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2017-11-25 04:07:05 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 882 bytes |
コンパイル時間 | 660 ms |
コンパイル使用メモリ | 55,296 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-27 09:18:01 |
合計ジャッジ時間 | 1,394 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 WA * 6 |
ソースコード
#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)) { int half = sum/2; bool dp[half+1][n+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[i+1][half]) { print("possible"); exit(0); } } } print("impossible"); return 0; }