結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2024-02-14 23:01:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,018 bytes |
コンパイル時間 | 922 ms |
コンパイル使用メモリ | 72,872 KB |
最終ジャッジ日時 | 2025-02-19 13:12:40 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 WA * 6 |
ソースコード
#include <iostream> #include <algorithm> using namespace std; //動的計画法を用いた解法 int main(void) { int N; cin >> N; int W[N]; int sum = 0; for (int i = 0; i < N; i++) { cin >> W[i]; sum += W[i]; } //cout << "sum: " << sum << endl; if (sum % 2) { cout << "impossible" << endl; } else { sort(W, W + N, greater<int>()); int tar = sum / 2; bool possible[N][sum / 2 + 1] {false}; possible[0][0] = true; for (int i = 1; i < N; i++) { for (int j = 0; j < tar + 1; j++) { if (possible[i-1][j]) { possible[i][j] = true; if (j + W[i] <= tar) { possible[i][j+W[i]] = true; } } } } if (possible[N-1][tar]) { cout << "possible" << endl; } else { cout << "impossible" << endl; } } return 0; return 0; }