結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-14 23:07:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,003 bytes |
| コンパイル時間 | 813 ms |
| コンパイル使用メモリ | 73,532 KB |
| 最終ジャッジ日時 | 2025-02-19 13:12:50 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 5 |
ソースコード
#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+1][tar + 1] {false};
possible[0][0] = true;
for (int i = 1; i < N + 1; i++) {
for (int j = 0; j < tar + 1; j++) {
if (possible[i-1][j]) {
possible[i][j] = true;
if (j + W[i-1] <= tar) {
possible[i][j+W[i-1]] = true;
}
}
}
}
if (possible[N][tar]) {
cout << "possible" << endl;
} else {
cout << "impossible" << endl;
}
}
return 0;
}