結果

問題 No.4 おもりと天秤
ユーザー kaffelunkaffelun
提出日時 2017-09-27 22:37:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 673 bytes
コンパイル時間 1,143 ms
コンパイル使用メモリ 145,616 KB
実行使用メモリ 7,468 KB
最終ジャッジ日時 2023-09-08 17:34:30
合計ジャッジ時間 2,146 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,264 KB
testcase_01 AC 4 ms
7,344 KB
testcase_02 AC 4 ms
7,264 KB
testcase_03 AC 4 ms
7,276 KB
testcase_04 AC 4 ms
7,324 KB
testcase_05 AC 6 ms
7,344 KB
testcase_06 AC 4 ms
7,332 KB
testcase_07 AC 6 ms
7,276 KB
testcase_08 AC 4 ms
7,264 KB
testcase_09 AC 4 ms
7,268 KB
testcase_10 AC 6 ms
7,268 KB
testcase_11 AC 4 ms
7,276 KB
testcase_12 AC 4 ms
7,428 KB
testcase_13 AC 5 ms
7,360 KB
testcase_14 AC 5 ms
7,340 KB
testcase_15 AC 5 ms
7,348 KB
testcase_16 AC 5 ms
7,324 KB
testcase_17 AC 4 ms
7,276 KB
testcase_18 AC 5 ms
7,468 KB
testcase_19 AC 6 ms
7,264 KB
testcase_20 AC 6 ms
7,268 KB
testcase_21 AC 6 ms
7,268 KB
testcase_22 AC 6 ms
7,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int N, S;
vector<int> W;

int dp[101][10001];

void recursive(int pos, int weight) {
	if(pos > N || dp[pos][weight]) return;
	dp[pos][weight] = 1;
	recursive(pos + 1, weight);
	recursive(pos + 1, weight + W[pos]);
}

int main() {
	cin >> N;
	W = vector<int>(N + 1);
	S = 0;
	for(int i = 0; i < N; i++) {
		cin >> W[i];
		S += W[i];
	}
	W[N] = 0;
	for(int i = 0; i < 101; i++) {
		for(int j = 0; j < 10001; j++) {
			dp[i][j] = 0;
		}
	}
	if(S % 2 == 1) {
		cout << "impossible" << endl;
		return 0;
	}
	recursive(0, 0);
	if(dp[N][S / 2]) {
		cout << "possible" << endl;
	} else {
		cout << "impossible" << endl;
	}
	return 0;
}
0