結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
KoshStorm
|
| 提出日時 | 2017-12-17 00:27:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 819 bytes |
| コンパイル時間 | 1,422 ms |
| コンパイル使用メモリ | 164,008 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-14 22:37:18 |
| 合計ジャッジ時間 | 2,094 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 WA * 3 |
ソースコード
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
using namespace std;
int main(void){
short N;
cin >> N;
vector<short> W(N);
long sum = 0;
REP(i,N){
cin >> W[i];
sum += W[i];
}
if (sum % 2) {
cout << "impossible\n";
exit(0);
}
#ifdef DEBUG
cout << "sum ==> " << sum << "\n";
#endif
vector<vector<short>>dp(N+1, vector<short>(sum/2+1, 0));
REP(i,N) dp[i][0] = 1;
REP(i,N){
REP(j,sum/2+1){
if ((j - W[j]) >= 0){
dp[i+1][j] = MAX(dp[i][j-W[i]],dp[i][j]);
}
}
}
#ifdef DEBUG
REP(i,N+1)
REP(j,sum/2+1)
cout << "dp[" << i << "][" << j << "] ==> " << dp[i][j] << "\n";
#endif
if (dp[N][sum/2]) cout << "possible\n";
else cout << "impossible\n";
return 0;
}
KoshStorm