結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2016-02-27 16:41:00 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 1,230 bytes |
コンパイル時間 | 754 ms |
コンパイル使用メモリ | 74,376 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 09:26:39 |
合計ジャッジ時間 | 1,590 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <cstdio> #include <iostream> #include <algorithm> #include <complex> #include <queue> #include <map> #include <string> using namespace std; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define pb push_back #define ALL(a) (a).begin(),(a).end() #define PI 3.1415926535 typedef long long ll; typedef pair<int, int> P; //typedef complex<double> C; const int MAX_N = 100; const int MAX_S = 10000; int N; int w[MAX_N]; int sum_w = 0; // dp[i][j] = i番目までの和がjとなるような重りの選び方があるか bool dp[MAX_N + 1][MAX_S + 1]; void input() { cin >> N; REP(i, N) { cin >> w[i]; sum_w += w[i]; } } void solve() { // 和が偶数でなければ2分割できない if (sum_w % 2 != 0) { cout << "impossible" << endl; return; } REP(i, N + 1) REP(j, MAX_S + 1) dp[i][j] = false; dp[0][0] = true; REP(i, N) { REP(j, MAX_S + 1) { if (dp[i][j]) { dp[i + 1][j + w[i]] = dp[i + 1][j] = true; } } } if (dp[N][sum_w / 2]) { cout << "possible" << endl; } else { cout << "impossible" << endl; } } int main() { input(); solve(); }