結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-30 10:10:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 711 bytes |
| コンパイル時間 | 907 ms |
| コンパイル使用メモリ | 74,716 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-19 02:35:34 |
| 合計ジャッジ時間 | 1,878 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 WA * 11 |
ソースコード
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> W(N);
int S = 0;
for (int i = 0; i < N; ++i) {
cin >> W[i];
S = W[i];
}
vector<vector<bool>> dp(N + 1, vector<bool>(S + 1, false));
dp[0][0] = true;
for (int i = 1; i <= N; ++i) {
for (int s = 0; s <= S; ++s) {
if (s + W[i - 1] <= S) {
dp[i][s] = dp[i - 1][s + W[i - 1]];
}
if (s - W[i - 1] >= 0) {
dp[i][s] = dp[i - 1][s - W[i - 1]];
}
}
}
if (dp[N][0]) {
cout << "possible" << endl;
} else {
cout << "impossible" << endl;
}
}