結果

問題 No.4 おもりと天秤
ユーザー TwizzTwizz
提出日時 2017-05-05 22:00:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 779 bytes
コンパイル時間 1,544 ms
コンパイル使用メモリ 165,020 KB
実行使用メモリ 7,632 KB
最終ジャッジ日時 2023-10-12 09:52:39
合計ジャッジ時間 2,565 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,532 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 WA -
testcase_03 AC 5 ms
7,364 KB
testcase_04 AC 4 ms
7,292 KB
testcase_05 AC 5 ms
7,300 KB
testcase_06 WA -
testcase_07 AC 4 ms
7,608 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 4 ms
7,304 KB
testcase_10 AC 4 ms
7,384 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 4 ms
7,292 KB
testcase_17 AC 4 ms
7,428 KB
testcase_18 WA -
testcase_19 AC 4 ms
7,424 KB
testcase_20 AC 5 ms
7,368 KB
testcase_21 AC 4 ms
7,288 KB
testcase_22 AC 5 ms
7,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
//const int mod = 1e9 + 7;

int n;
int w[102];
int sum = 0;
int half = 0;
int dp[102][10000];

int solve(int i, int sum) {
	if (dp[i][sum] != -1)return dp[i][sum];
	if (i == n&&sum == half) { return dp[i][sum] = 1; }
	if (solve(i + 1, sum)) { return dp[i+1][sum] = 1; }
	if (solve(i + 1, sum + w[i])) { return dp[i+1][sum+w[i]] = 1; }
	return dp[i][sum] = 0;
}

int main() {
	cin >> n;
	rep(i, 0, n) { cin >> w[i]; half += w[i]; }
	if (half % 2 == 1) {
		print("impossible"); return 0;
	}
	half /= 2;
	memset(dp, -1, sizeof(dp));
	if (solve(0, 0)) { print("possible"); }
	else { print("impossible"); }
	return 0;
}
0