結果

問題 No.602 隠されていたゲーム2
ユーザー olphe
提出日時 2017-12-02 00:33:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,496 bytes
コンパイル時間 1,128 ms
コンパイル使用メモリ 101,664 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-15 23:57:31
合計ジャッジ時間 1,997 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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