結果

問題 No.4 おもりと天秤
ユーザー w10y26w10y26
提出日時 2017-05-08 10:18:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,033 bytes
コンパイル時間 2,087 ms
コンパイル使用メモリ 77,052 KB
実行使用メモリ 5,176 KB
最終ジャッジ日時 2023-09-08 17:26:32
合計ジャッジ時間 1,702 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,984 KB
testcase_01 AC 3 ms
5,092 KB
testcase_02 AC 3 ms
4,992 KB
testcase_03 AC 3 ms
5,052 KB
testcase_04 AC 3 ms
5,052 KB
testcase_05 AC 4 ms
5,072 KB
testcase_06 AC 4 ms
5,048 KB
testcase_07 AC 4 ms
5,056 KB
testcase_08 AC 3 ms
5,056 KB
testcase_09 AC 4 ms
5,052 KB
testcase_10 AC 4 ms
5,072 KB
testcase_11 AC 3 ms
5,176 KB
testcase_12 AC 3 ms
5,048 KB
testcase_13 AC 3 ms
4,988 KB
testcase_14 AC 3 ms
4,984 KB
testcase_15 AC 3 ms
5,048 KB
testcase_16 AC 3 ms
5,048 KB
testcase_17 AC 4 ms
5,048 KB
testcase_18 AC 4 ms
5,052 KB
testcase_19 AC 4 ms
4,988 KB
testcase_20 AC 3 ms
4,988 KB
testcase_21 AC 4 ms
5,048 KB
testcase_22 AC 4 ms
4,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(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--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;
bool dp[101][SIZE];

//dp[i番目のとき][左側の重さ]
int main(){
	
	rep(i,101){
		rep(j,10001) dp[i][j] = false;
	}

	int n;
	vector<int> v(100);
	cin >> n;
	rep(i,n) cin >> v[i];

	int sum = 0;
	rep(i,n) sum += v[i];

	if(sum%2 == 1){
		cout << "impossible" << endl;
		return 0;
	}

	dp[0][0] = true;
	rep(i,n){
		rep(j,10001){
			if(dp[i][j]){//全パターンのメモを行う.
				//左側の天秤に入れる
				dp[i+1][j+v[i]] = true;
				//右側の天秤に入れる
				dp[i+1][j] = true;
			}
		}
	}
	
	cout << ((dp[n][sum/2])?"possible":"impossible")<<endl;
	return 0;
}
0