結果

問題 No.4 おもりと天秤
ユーザー sekiya9311sekiya9311
提出日時 2016-05-02 01:31:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,380 bytes
コンパイル時間 1,315 ms
コンパイル使用メモリ 109,244 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 08:39:37
合計ジャッジ時間 2,049 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
6,944 KB
testcase_07 WA -
testcase_08 AC 2 ms
6,944 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
6,940 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*------------------------------------------*/
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <bitset>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define RREP(i,a) for(int (i)=(a)-1;(i)>=0;(i)--)
#define FORR(i,a,b) for(int (i)=(a)-1;(i)>=(b);(i)--)
#define MOD 1e9+7
#define PI acos(-1.0)
#define DEBUG(C) cout<<C<<endl;	//デバッグ用マクロ

typedef long long LL;
typedef unsigned long long ULL;

using namespace std;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<bool> dp(10000,false);	//dp[i]=trueならば重さiの組み合わせ可能

bool solve(int target,vector<int> a){
	dp[0]=true;
	REP(i,a.size()) if(dp[i]) dp[i+a[i]]=true;
	if(dp[target]) return true;
	else return false;
}

int main(){
	int N; cin>>N;
	vector<int> A(N);
	int target=0;
	REP(i,N) {cin>>A[i]; target+=A[i];}
	if(target&1) cout<<"impossible"<<endl;
	else{
		sort(A.begin(),A.end());
		if(solve(target/2,A)) cout<<"possible"<<endl;
		else cout<<"impossible"<<endl;
	}
}
0