結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-12-08 16:02:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 191 ms / 5,000 ms |
| コード長 | 885 bytes |
| コンパイル時間 | 2,022 ms |
| コンパイル使用メモリ | 167,488 KB |
| 実行使用メモリ | 398,164 KB |
| 最終ジャッジ日時 | 2024-07-16 07:09:30 |
| 合計ジャッジ時間 | 7,024 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int n;
int w[101];
int sum;
int dp[101][1000001];
const int mod = 1000000009;
int recu(int N, int W){
int res = 0;
if (dp[N][W] > -1) return dp[N][W];
if (N <= 0){
dp[N][W] = 0;
return dp[N][W];
}
if (W == 0){
dp[N][W] = 1;
return dp[N][W];
}
res = recu(N - 1,W);
if (w[N - 1] <= W){
res = (res + recu(N - 1, W - w[N - 1]))%mod;
}
dp[N][W] = res;
return res;
}
int main(){
memset(dp,-1, sizeof(dp));
sum = 0;
dp[0][0] = 1;
cin >> n;
for (int i = 0; i < n; ++i){
cin >> w[i];
sum += w[i];
}
if (sum%2 != 0){
cout << "impossible" << endl;
return 0;
}
sum = sum/2;
int res = recu(n, sum);
if (res > 0) cout << "possible" << endl;
else cout << "impossible" << endl;
}