結果

問題 No.4 おもりと天秤
ユーザー gunmanekogunmaneko
提出日時 2019-09-18 20:58:17
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,330 bytes
コンパイル時間 1,875 ms
コンパイル使用メモリ 150,368 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-23 01:59:36
合計ジャッジ時間 2,963 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 WA -
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int locks(int, int, std::vector<int>)’:
main.cpp:50:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^

ソースコード

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 locks(int a, int b,vector<int> c) {
	int k = a;
	int d = b;
	if (a == 0) {
		return 1;
	}
	if (d >= c.size()) {
		return 0;
	}
	if (a < 0) {
		return 0;
	}
	if (locks(a - c[b], b + 1, c) == 1) {
		return 1;
	}
	if (locks(a, b + 1, c)) {
		return 1;
	}
}
int N;
vector<int>c;
int numbers = 0;
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		c.push_back(a);
		numbers = a + numbers;
	}
	sort(c.begin(), c.end(), greater<int>());
	if (numbers % 2 != 0) {
		cout << "impossible";
	}
	else {
		numbers = numbers / 2;
		int o = locks(numbers, 0, c);
		if (o != 0) {
			cout << "possible";
		}
		else {
			cout << "impossible";
		}
	}
}
0