結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-11 23:55:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 1,092 bytes |
| コンパイル時間 | 1,739 ms |
| コンパイル使用メモリ | 173,636 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-18 10:47:29 |
| 合計ジャッジ時間 | 2,599 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
vector<int>vec;
vector<vector<int>>dp;
int avg;
int N;
int dfs(int i, int now) {
if (dp[i][now] != -1) return dp[i][now];
if (i == 0) {
if (now == 0) return 1;
return 0;
}
int res = 0;
int n = vec[i-1];
if (now >= n && dfs(i-1, now-n) == 1) res = 1;
if (dfs(i-1, now) == 1) res = 1;
return dp[i][now] = res;
}
int main()
{
cin >> N;
vec.resize(N);
int sum = 0;
for (int i=0; i<N; i++) {
cin >> vec.at(i);
sum += vec[i];
}
avg = sum/2;
dp.assign(N+1, vector<int>(avg+1, -1));
if (sum % 2 != 0) {
cout << "impossible" << endl;
} else {
if (dfs(N, avg) == 1) {
cout << "possible" << endl;
} else {
cout << "impossible" << endl;
}
}
return 0;
}