結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2018-06-28 15:12:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 836 bytes |
コンパイル時間 | 576 ms |
コンパイル使用メモリ | 64,948 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-30 23:27:22 |
合計ジャッジ時間 | 5,064 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 WA * 21 |
ソースコード
#include <iostream> #include <string.h> using namespace std; int main(){ int n; cin >> n; int weight[n]; int sum_weight = 0; for (int i = 0; i < n; i++){ cin >> weight[i]; sum_weight += weight[i]; } if (sum_weight % 2 == 1){ cout << "impossible" << endl; return 0; } int half_weight = sum_weight / 2; // 重さjを作れるか int dp[half_weight + 1]; memset(dp, 0, sizeof(dp)); dp[0] = 1; for (int i = 0; i < n; i++){ int w = weight[i]; for (int j = 0; j <= half_weight - w; j++){ cout << dp[j + w] << " " << dp[j] << endl; dp[j + w] |= dp[j]; } } if (dp[half_weight] == 1){ cout << "possible" << endl; } else { cout << "impossible" << endl; } return 0; }