結果
| 問題 | No.4 おもりと天秤 |
| コンテスト | |
| ユーザー |
assy1028
|
| 提出日時 | 2015-03-20 18:58:37 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 989 bytes |
| 記録 | |
| コンパイル時間 | 456 ms |
| コンパイル使用メモリ | 99,828 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2026-03-13 01:32:37 |
| 合計ジャッジ時間 | 1,133 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <complex>
#include <string.h>
using namespace std;
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
typedef long long ll;
typedef pair<int, int> P;
typedef unsigned int uint;
const int inf = 1000000009;
bool solve(int n) {
int w[n];
int sum = 0;
for (int i = 0; i < n; i++) {
int v;
scanf("%d", &v);
sum += v;
w[i] = v;
}
if (sum % 2 == 1) return false;
bool can[sum+1];
memset(can, false, sizeof(can));
can[0] = true;
for (int i = 0; i < n; i++) {
for (int j = sum; j >= 0; j--) {
if (can[j])
can[j+w[i]] = true;
}
}
return can[sum/2];
}
int main() {
int n;
scanf("%d", &n);
printf("%s\n", solve(n) ? "possible" : "impossible");
}
assy1028