結果

問題 No.602 隠されていたゲーム2
ユーザー zscoderzscoder
提出日時 2017-12-02 10:49:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,586 bytes
コンパイル時間 2,624 ms
コンパイル使用メモリ 181,248 KB
実行使用メモリ 4,592 KB
最終ジャッジ日時 2023-08-22 05:37:18
合計ジャッジ時間 3,806 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 19 ms
4,380 KB
testcase_19 AC 22 ms
4,496 KB
testcase_20 AC 23 ms
4,592 KB
testcase_21 AC 19 ms
4,580 KB
testcase_22 AC 15 ms
4,488 KB
testcase_23 AC 17 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

ll mx[2];
ll a[111111];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	mx[0]=-ll(1e9); mx[1]=-ll(1e9);
	vi V[2];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		V[a[i]&1].pb(a[i]);
		mx[a[i]&1]=max(mx[a[i]&1],a[i]);
	}
	ll x,y; cin>>x>>y;
	ll D = abs(x)+abs(y);
	if(D==0){cout<<0<<'\n'; return 0;}
	for(int i=0;i<n;i++)
	{
		if(a[i]==D){cout<<1<<'\n'; return 0;}
	}
	ll mxeven=max(mx[0]*2,mx[1]*2);
	if(D&1)
	{
		sort(V[0].begin(),V[0].end());
		sort(V[1].begin(),V[1].end());
		for(int i=0;i<V[1].size();i++)
		{
			int lb=lower_bound(V[0].begin(),V[0].end(),V[1][i])-V[0].begin();
			lb--;
			if(lb>=0)
			{
				if(V[1][i]-V[0][lb]<=D&&D<=V[1][i]+V[0][lb])
				{
					cout<<2<<'\n'; return 0;
				}
			}
		}
		swap(V[0],V[1]);
		for(int i=0;i<V[1].size();i++)
		{
			int lb=lower_bound(V[0].begin(),V[0].end(),V[1][i])-V[0].begin();
			lb--;
			if(lb>=0)
			{
				if(V[1][i]-V[0][lb]<=D&&D<=V[1][i]+V[0][lb])
				{
					cout<<2<<'\n'; return 0;
				}
			}
		}
		cout<<-1<<'\n';
	}
	else
	{
		cout<<(D<=mxeven?2:-1)<<'\n';
	}
}
0