結果

問題 No.4 おもりと天秤
ユーザー Naoyk1212Naoyk1212
提出日時 2017-06-07 14:52:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 330 ms / 5,000 ms
コード長 804 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 85,276 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 17:30:08
合計ジャッジ時間 3,435 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 7 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 170 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 171 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 182 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 330 ms
4,380 KB
testcase_19 AC 141 ms
4,376 KB
testcase_20 AC 130 ms
4,376 KB
testcase_21 AC 142 ms
4,380 KB
testcase_22 AC 135 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <complex>
#include <cmath>
#include <ccomplex>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		sum += v[i];
	}

	if (sum % 2 != 0) {
		cout << "impossible" << endl;
		return 0;
	}
	else {
		sum /= 2;
	}
	
	bool dp[10010];
	for (int i = 0; i < 10010; i++)dp[i] = false;

	dp[0] = true;
	
	for (int i = 0; i < n; i++) {
		for (int j = sum * 2; j >= 0; j--) {
			if (dp[j]) {
				cerr << j + v[i] << endl;
				dp[j + v[i]] = true;
				if (j + v[i] == sum) {
					cout << "possible" << endl;
					return 0;
				}
			}
		}
	}
	cout << "impossible" << endl;
	
}
0