結果

問題 No.602 隠されていたゲーム2
ユーザー creep04creep04
提出日時 2017-12-02 04:52:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,262 bytes
コンパイル時間 3,679 ms
コンパイル使用メモリ 151,276 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 05:37:09
合計ジャッジ時間 3,908 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

int n, x, y, t;
long long D;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> n;
	vector<long long> even, odd;
	for (int i = 0; i < n; ++i) {
		cin >> t;
		if (t%2==0) even.push_back(t);
		else odd.push_back(t);
	}
	sort(even.begin(), even.end());
	sort(odd.begin(), odd.end());
	cin >> x >> y;
	D = abs(x) + abs(y);
	
	if (D==0) {
		cout << 0 << "\n";
		return 0;
	}
	if (binary_search(even.begin(), even.end(), D)
		|| binary_search(odd.begin(), odd.end(), D)) {
		cout << 1 << "\n";
		return 0;
	}
	for (auto itr: even) {
		long long fr = abs(itr-D), to = itr + D;
		if ((to%2==0 && lower_bound(even.begin(), even.end(), to)
					   - lower_bound(even.begin(),even.end(), fr) > 0) ||
				(to%2==1 && lower_bound(odd.begin(), odd.end(), to)
							- lower_bound(odd.begin(),odd.end(), fr) > 0)) {
			cout << 2 << "\n";
			return 0;
		}
	}
	for (auto itr: odd) {
		long long fr = abs(itr-D), to = itr + D;
		if ((to%2==0 && lower_bound(even.begin(), even.end(), to)
						- lower_bound(even.begin(),even.end(), fr) > 0) ||
			(to%2==1 && lower_bound(odd.begin(), odd.end(), to)
						- lower_bound(odd.begin(),odd.end(), fr) > 0)) {
			cout << 2 << "\n";
			return 0;
		}
	}
	cout << -1 << "\n";
}
0