結果

問題 No.4 おもりと天秤
ユーザー gunmanekogunmaneko
提出日時 2019-09-25 02:56:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,110 bytes
コンパイル時間 3,413 ms
コンパイル使用メモリ 159,308 KB
実行使用メモリ 7,836 KB
最終ジャッジ日時 2023-10-19 19:35:58
合計ジャッジ時間 4,569 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int dp[120][10200] = {};
int main() {
	int N;
	cin >> N;
	dp[0][0] = 1;
	int sum = 0;
	for (int i = 1; i <= N; i++) {
		int a;
		cin >> a;
		sum = sum + a;
		for (int j = 0; j < 10000; j++) {
			if (dp[i - 1][j] == 1) {
				dp[i][j + a] = 1;
			}
		}
	}
	if (sum % 2 == 1) {
		cout << "impossible";
		return 0;
	}

	for (int i = 0; i < N; i++) {
		if (dp[i][sum / 2] == 1) {
			cout << "possible";
			return 0;
		}
	}

	cout << "impossible";
}
0