結果

問題 No.602 隠されていたゲーム2
ユーザー eto_nagisaeto_nagisa
提出日時 2017-12-03 02:38:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 2,034 bytes
コンパイル時間 1,291 ms
コンパイル使用メモリ 152,324 KB
実行使用メモリ 5,144 KB
最終ジャッジ日時 2023-08-22 05:39:37
合計ジャッジ時間 2,637 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 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 6 ms
4,376 KB
testcase_17 AC 11 ms
4,384 KB
testcase_18 AC 18 ms
4,820 KB
testcase_19 AC 23 ms
5,144 KB
testcase_20 AC 25 ms
4,912 KB
testcase_21 AC 16 ms
4,960 KB
testcase_22 AC 25 ms
4,816 KB
testcase_23 AC 17 ms
4,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vl v(n);
	REP(i, n)cin >> v[i];
	ll x, y;
	cin >> x >> y;
	if (x == 0 && y == 0) {
		cout << 0 << endl;
		return 0;
	}
	vl o, e;
	REP(i, n) {
		if (v[i] % 2 == 0)e.push_back(v[i]);
		else o.push_back(v[i]);
	}
	sort(ALL(o));
	sort(ALL(e));
	ll dist = abs(x) + abs(y);
	REP(i, n) {
		if (v[i] == dist) {
			cout << 1 << endl;
			return 0;
		}
	}
	REP(i, n) {
		if ((dist - v[i]) % 2 == 0) {
			int c;
			if (dist <= v[i]) {
				c = lower_bound(ALL(e), v[i] - dist) - e.begin();
			}
			else {
				c = lower_bound(ALL(e), dist - v[i]) - e.begin();

			}
			if (c != e.size() && e[c] <= dist + v[i]) {
				cout << 2 << endl;
				return 0;
			}

		}
		else {
			int c;
			if (dist <= v[i]) {
				c = lower_bound(ALL(o), v[i] - dist) - o.begin();
			}
			else {
				c = lower_bound(ALL(o), dist - v[i]) - o.begin();

			}
			if (c != o.size() && o[c] <= dist + v[i]) {
				cout << 2 << endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;

}
0