結果

問題 No.4 おもりと天秤
ユーザー gunmanekogunmaneko
提出日時 2019-09-25 03:03:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,130 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 159,504 KB
実行使用メモリ 7,880 KB
最終ジャッジ日時 2023-10-19 19:47:21
合計ジャッジ時間 2,775 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
				dp[i][j] = 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