結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
soupesuteaka
|
| 提出日時 | 2014-12-29 01:20:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 950 bytes |
| コンパイル時間 | 659 ms |
| コンパイル使用メモリ | 84,044 KB |
| 実行使用メモリ | 7,416 KB |
| 最終ジャッジ日時 | 2024-06-26 09:04:36 |
| 合計ジャッジ時間 | 1,560 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <iomanip>
#define INF 1000000001
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const double PI = acos(-1.0);
int N;
int W[101];
int dp[10001][101];
int main()
{
ios::sync_with_stdio(false);
cin >> N;
FOR(i,0,N) cin >> W[i];
memset(dp, 0, sizeof(dp));
int s=0;
FOR(i,0,N) s+=W[i];
if (s%2) {
cout << "impossible\n";
} else {
s/=2;
FOR(i,0,N+1) dp[0][i] = 1;
FOR(i,1,s+1) FOR(j,1,N+1) {
dp[i][j] = dp[i][j-1];
if (i-W[j-1]>=0) dp[i][j] |= dp[i-W[j-1]][j-1];
}
if (dp[s][N]) cout << "possible\n";
else cout << "impossible\n";
}
return 0;
}
soupesuteaka