結果
問題 | No.4 おもりと天秤 |
ユーザー |
![]() |
提出日時 | 2016-10-02 05:50:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 934 bytes |
コンパイル時間 | 1,538 ms |
コンパイル使用メモリ | 172,484 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 10:01:34 |
合計ジャッジ時間 | 2,301 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
外部呼び出し有り |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include "bits/stdc++.h" #define debug(x) cout<<#x<<": "<<x<<endl #define rep(i,n) for (int i=0;i<(n);i++) #define FOR(i,a,b) for (int i=(a);i<=(b);i++) #define all(a) (a).begin(),(a).end() using namespace std; typedef vector<int> VI; typedef vector<vector<int>> VVI; typedef long long ll; void solve() { #ifdef _WIN32 istream &cin = ifstream("input.txt"); #endif int n, sum = 0; cin >> n; VI v(n); rep(i, n) { cin >> v[i]; sum += v[i]; } if (sum % 2 == 1) { cout << "impossible" << endl; return; } sum /= 2; VVI dp(n + 1, VI(sum + 1)); rep(i, n + 1) dp[i][0] = 1; rep(i, n + 1) { rep(j, sum + 1) { if (i == 0) continue; if (dp[i - 1][j] == 1) dp[i][j] = 1; if (j - v[i - 1] >= 0 && dp[i - 1][j - v[i - 1]]) dp[i][j] = 1; } } cout << (dp[n][sum] == 1 ? "possible" : "impossible") << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); system("PAUSE"); return 0; }