結果

問題 No.602 隠されていたゲーム2
ユーザー olpheolphe
提出日時 2017-12-02 00:33:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,496 bytes
コンパイル時間 1,013 ms
コンパイル使用メモリ 100,256 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 05:33:02
合計ジャッジ時間 2,355 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N;
	vector<long long int>o;
	vector<long long int>e;
	for (int i = 0; i < N; i++) {
		cin >> M;
		if (M % 2) {
			o.push_back(M);
		}
		else {
			e.push_back(M);
		}
	}
	long long int a, b;
	cin >> a >> b;
	a = abs(a);
	b = abs(b);
	if (!a && !b) {
		cout << "0\n";
		return 0;
	}
	for (auto i : e) {
		if (i == a + b) {
			cout << "1\n";
			return 0;
		}
	}
	for (auto i : o) {
		if (i == a + b) {
			cout << "1\n";
			return 0;
		}
	}
	sort(o.begin(), o.end());
	sort(e.begin(), e.end());
	if ((a + b) % 2) {
		for (auto i : o) {
			L = abs(a + b - i);
			R = a + b + i;
			if (lower_bound(e.begin(), e.end(), L) != upper_bound(e.begin(), e.end(), R)) {
				cout << "2\n";
				return 0;
			}
		}
	}
	else {
		for (auto i : e) {
			L = abs(a + b - i);
			R = a + b + i;
			if (lower_bound(e.begin(), e.end(), L) != upper_bound(e.begin(), e.end(), R)) {
				cout << "2\n";
				return 0;
			}
		}
		for (auto i : o) {
			L = abs(a + b - i);
			R = a + b + i;
			if (lower_bound(o.begin(), o.end(), L) != upper_bound(o.begin(), o.end(), R)) {
				cout << "2\n";
				return 0;
			}
		}
	}
	cout << "-1\n";
	return 0;
}
0