結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
togatoga
|
| 提出日時 | 2015-07-30 20:50:01 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,355 bytes |
| コンパイル時間 | 876 ms |
| コンパイル使用メモリ | 90,604 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-17 22:40:16 |
| 合計ジャッジ時間 | 1,633 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 WA * 8 |
ソースコード
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <algorithm>
#include <functional>
#include <limits.h>
#include <bitset>
#include <tuple>
#include <unordered_map>
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
int dp[110][2500];
vector<int> weight;
int memo(int pos, int sum) {
if (pos == N) {
if (sum == 1250) {
return 1;
} else {
return 0;
}
}
if (dp[pos][sum] >= 0) {
return dp[pos][sum];
}
int res = 0;
res |= memo(pos + 1, sum + weight[pos]);
res |= memo(pos + 1, sum - weight[pos]);
return dp[pos][sum] = res;
}
int main() {
int pos = 1250;
memset(dp, -1, sizeof(dp));
cin >> N;
for (int i = 0; i < N; i++) {
int x;
cin >> x;
weight.push_back(x);
}
if (memo(0, pos) == 1) {
cout << "possible" << endl;
} else {
cout << "impossible" << endl;
}
return 0;
}
togatoga