結果

問題 No.602 隠されていたゲーム2
ユーザー NekosyndromeNekosyndrome
提出日時 2017-12-02 05:01:51
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,560 bytes
コンパイル時間 1,758 ms
コンパイル使用メモリ 166,776 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-05 20:39:03
合計ジャッジ時間 4,333 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 RE -
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 10 ms
5,376 KB
testcase_17 AC 21 ms
5,376 KB
testcase_18 RE -
testcase_19 AC 72 ms
5,376 KB
testcase_20 AC 61 ms
5,376 KB
testcase_21 AC 44 ms
5,376 KB
testcase_22 AC 59 ms
5,376 KB
testcase_23 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int n;
LL d[M],xt,yt;
vector<LL> d2[2];

pair<LL,LL> dis(LL x,pair<LL,LL> y)
{
	if (x < y.F)
		return MP(y.F-x, y.S-x);
	if (x > y.S)
		return MP(x-y.S, x-y.F);
	return MP(
		0LL, 
		max(x-y.F, y.S-x)
	);
}
LL findBetween(LL x,LL y,int z) //[x,y]
{
	if(z==-1) z=1;
	int pos = lower_bound(d2[z].begin(), d2[z].end(), x) - d2[z].begin();
	if(pos<(int)d2[z].size() && d2[z][pos]<=y) return d2[z][pos];
	return -1;
}
int getans(LL dd)
{
	if(dd == max(abs(xt), abs(yt)))
		return 1;
	
	LL tmp, tmp2;
	pair<LL,LL> rng;
	
	// +-dd, ?
	rng = dis(yt, MP(-dd, dd)); //dy
	if (rng.F%2 != (dd+yt)%2) rng.F++;
	if (rng.S%2 != (dd+yt)%2) { rng.S--; assert(0); }
	if (rng.F > rng.S) {
		assert(0);
		rng = MP(1LL<<62, (1LL<<62)*-1);
	}

	tmp2 = min(abs(xt-dd), abs(xt+dd));
	if (rng.S >= tmp2) {
		tmp = findBetween(max(rng.F,tmp2), rng.S, (dd+yt)%2);
		if(tmp!=-1) return 2;
	}
	if (rng.F <= tmp2) {
		tmp = findBetween(tmp2, tmp2, tmp2%2);
		if(tmp!=-1) return 2;
	}
	tmp2 = max(abs(xt-dd), abs(xt+dd));
	if (rng.F <= tmp2) {
		tmp = findBetween(tmp2, tmp2, tmp2%2);
		if(tmp!=-1) return 2;
	}

	// ?, +-dd
	rng = dis(xt, MP(-dd, dd));
	
	tmp2 = min(abs(yt-dd), abs(yt+dd));
	if (rng.F%2 != (dd+xt)%2) rng.F++;
	if (rng.S%2 != (dd+xt)%2) { rng.S--; assert(0); }
	if (rng.F > rng.S) {
		assert(0);
		rng = MP(1LL<<62, (1LL<<62)*-1);
	}
	
	if (rng.S >= tmp2) {
		tmp = findBetween(max(rng.F,tmp2), rng.S, (dd+xt)%2);
		if(tmp!=-1) return 2;
	}
	if (rng.F <= tmp2) {
		tmp = findBetween(tmp2, tmp2, tmp2%2);
		if(tmp!=-1) return 2;
	}
	tmp2 = max(abs(yt-dd), abs(yt+dd));
	if (rng.F <= tmp2) {
		tmp = findBetween(tmp2, tmp2, tmp2%2);
		if(tmp!=-1) return 2;
	}

	return 3;
}
int main()
{
	while(~scanf("%d",&n))
	{
		d2[0].clear();
		d2[1].clear();
		REP(i,1,n) {
			cin >> d[i];
			d2[d[i]%2].PB(d[i]);
		}
		sort(d+1, d+n+1);
		sort(d2[0].begin(), d2[0].end());
		sort(d2[1].begin(), d2[1].end());

		cin >> xt >> yt;

		{
			LL x2 = xt;
			xt += yt;
			yt = x2 - yt;
		}

		int ans=3;
		REP(i,1,n) ans = min(ans, getans(d[i]));
		if(ans==3) ans=-1;
		printf("%d\n", ans);

	}
	return 0;
}

0