結果
| 問題 |
No.602 隠されていたゲーム2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-02 03:44:56 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,078 bytes |
| コンパイル時間 | 1,560 ms |
| コンパイル使用メモリ | 162,196 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-28 02:33:58 |
| 合計ジャッジ時間 | 3,061 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 4 |
ソースコード
#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;
}