結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-10 21:44:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 792 bytes |
| コンパイル時間 | 669 ms |
| コンパイル使用メモリ | 74,752 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-22 23:24:49 |
| 合計ジャッジ時間 | 2,454 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 RE * 8 |
ソースコード
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int N;
cin >> N;
vector<int> W(N);
int sum = 0;
for (int i = 0; i < N; i++)
{
cin >> W[i];
sum += W[i];
}
if (sum % 2)
{
cout << "impossible" << endl;
return 0;
}
sum /= 2;
vector<vector<bool>> dp(N + 1, vector<bool>(sum + 1, false));
dp[0][0] = true;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < sum; j++)
{
if (!dp[i][j])
{
continue;
}
dp[i + 1][j] = true;
dp[i + 1][j + W[i]] = true;
}
}
if (dp[N][sum])
{
cout << "possible" << endl;
}
else
{
cout << "impossible" << endl;
}
}