結果

問題 No.4 おもりと天秤
ユーザー takune1024
提出日時 2017-11-27 22:53:49
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 777 bytes
コンパイル時間 593 ms
コンパイル使用メモリ 66,148 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 10:24:50
合計ジャッジ時間 1,270 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

typedef pair<int, int> P;
typedef unsigned long long ll;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))

const int inf = 999999999;
const int mod = 1000000007;

bool dp[110][10010];

int main(){
	int n; cin >> n;
	int w[n], W = 0;
	Rep(i, n){
		cin >> w[i];
		W += w[i];
	}
	dp[0][0] = true;
	Rep(i, n) Rep(j, W + 1){
		if(j >= w[i]){
			if(dp[i][j - w[i]] || dp[i][j]) dp[i + 1][j] = true;
		}else{
			if(dp[i][j]) dp[i + 1][j] = true;
		}
	}
	if(W % 2 == 0){
		if(dp[n][W / 2] > 0) cout << "possible" << endl;
		else cout << "impossible" << endl;
	}else{
		cout << "impossible" << endl;
	}
	return 0;
}
0