結果

問題 No.4 おもりと天秤
ユーザー ark27ark27
提出日時 2019-07-25 11:29:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 864 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 165,364 KB
実行使用メモリ 4,676 KB
最終ジャッジ日時 2023-09-14 23:44:50
合計ジャッジ時間 2,745 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,388 KB
testcase_01 AC 3 ms
4,504 KB
testcase_02 AC 3 ms
4,392 KB
testcase_03 AC 3 ms
4,524 KB
testcase_04 AC 3 ms
4,420 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 2 ms
4,428 KB
testcase_07 AC 4 ms
4,424 KB
testcase_08 AC 4 ms
4,452 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 4 ms
4,416 KB
testcase_11 AC 2 ms
4,428 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,448 KB
testcase_14 AC 2 ms
4,516 KB
testcase_15 AC 3 ms
4,456 KB
testcase_16 AC 2 ms
4,528 KB
testcase_17 AC 3 ms
4,416 KB
testcase_18 AC 5 ms
4,396 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 4 ms
4,412 KB
testcase_21 AC 4 ms
4,676 KB
testcase_22 AC 4 ms
4,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){return a/GCD(a,b)*b;}

int main(){
	int n;
	cin >> n;
	int w[110],sum=0;
	FOR(i,n){
		cin >> w[i+1];
		sum+=w[i+1];
	}

	bool dp[110][10010]={0};
	dp[0][0]=1;


	for(int i=1;i<=n;i++){
		for(int j=0;j<=10000;j++){
			if(j-w[i]>=0){
				if(dp[i-1][j] || dp[i-1][j-w[i]]){
					dp[i][j]=1;
				}
			}
		}
	}

	if(dp[n][sum/2] && sum%2==0){
		cout << "possible" << endl;
	}else{
		cout << "impossible" << endl;
	}




}
0