結果

問題 No.602 隠されていたゲーム2
ユーザー NekosyndromeNekosyndrome
提出日時 2017-12-02 03:44:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,078 bytes
コンパイル時間 1,360 ms
コンパイル使用メモリ 163,616 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-06 00:52:31
合計ジャッジ時間 2,696 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 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 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 WA -
testcase_17 AC 24 ms
5,376 KB
testcase_18 AC 57 ms
5,376 KB
testcase_19 AC 76 ms
5,376 KB
testcase_20 AC 66 ms
5,376 KB
testcase_21 AC 48 ms
5,376 KB
testcase_22 AC 71 ms
5,376 KB
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

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;

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(
		0, 
		max(x-y.F, y.S-x)		
	);
}
LL findBetween(LL x,LL y) //[x,y]
{
	int pos = lower_bound(d+1, d+n+1, x) - d;
	if(pos<=n && d[pos]<=y) return d[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
	tmp = findBetween(rng.F, rng.S);
	tmp2 = min(abs(xt-dd), abs(xt+dd));

	if(tmp>=0 && tmp2<=tmp)
		return 2;
	else {
		LL tmp3 = findBetween(tmp2, tmp2);
		if(tmp3!=-1 && rng.F<=tmp3 && tmp3<=rng.S)
			return 2;
	}

	tmp2 = max(abs(xt-dd), abs(xt+dd));
	if(tmp>=0 && tmp2<=tmp)
		return 2;
	else {
		LL tmp3 = findBetween(tmp2, tmp2);
		if(tmp3!=-1 && rng.F<=tmp3 && tmp3<=rng.S)
			return 2;
	}

	// ?, +-dd
	rng = dis(xt, MP(-dd, dd));
	tmp = findBetween(rng.F, rng.S);
	tmp2 = min(abs(yt-dd), abs(yt+dd));

	if(tmp>=0 && tmp2<=tmp)
		return 2;
	else {
		LL tmp3 = findBetween(tmp2, tmp2);
		if(tmp3!=-1 && rng.F<=tmp3 && tmp3<=rng.S)
			return 2;
	}

	tmp2 = max(abs(yt-dd), abs(yt+dd));
	if(tmp>=0 && tmp2<=tmp)
		return 2;
	else {
		LL tmp3 = findBetween(tmp2, tmp2);
		if(tmp3!=-1 && rng.F<=tmp3 && tmp3<=rng.S)
			return 2;
	}
	return 3;
}
int main()
{
	while(~scanf("%d",&n))
	{
		REP(i,1,n) cin >> d[i];
		sort(d+1, d+n+1);
		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