結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 1 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 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 15 ms
5,376 KB
testcase_18 AC 41 ms
5,376 KB
testcase_19 AC 50 ms
5,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 51 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

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

	// ?, +-dd
	rng = dis(xt, MP(-dd, dd));
	
	tmp2 = min(abs(yt-dd), abs(yt+dd));
	if (rng.S >= tmp2) {
		tmp = findBetween(max(rng.F,tmp2), rng.S);
		if(tmp!=-1) return 2;
	}
	if (rng.F <= tmp2) {
		tmp = findBetween(tmp2, tmp2);
		if(tmp!=-1) return 2;
	}
	tmp2 = max(abs(yt-dd), abs(yt+dd));
	if (rng.F <= tmp2) {
		tmp = findBetween(tmp2, tmp2);
		if(tmp!=-1) 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