結果

問題 No.602 隠されていたゲーム2
ユーザー lyozlyoz
提出日時 2017-12-02 01:12:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 2,596 bytes
コンパイル時間 2,196 ms
コンパイル使用メモリ 206,360 KB
実行使用メモリ 5,772 KB
最終ジャッジ日時 2023-08-22 05:34:59
合計ジャッジ時間 3,440 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 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,376 KB
testcase_13 AC 1 ms
4,376 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 9 ms
4,376 KB
testcase_18 AC 20 ms
5,416 KB
testcase_19 AC 23 ms
5,752 KB
testcase_20 AC 28 ms
5,664 KB
testcase_21 AC 21 ms
5,772 KB
testcase_22 AC 22 ms
4,616 KB
testcase_23 AC 17 ms
5,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int solve(vl ds,ll x,ll y)
{
	sort(all(ds));
	ll u=abs(x-y),v=abs(x+y);

	if(u==0&&v==0) return 0;

	for(auto d:ds) if(max(u,v)==d) return 1;

	if(u%2==0){
		for(auto d:ds) if(max(u,v)<=2*d) return 2;
	}
	else{
		vl es,os;
		for(auto d:ds)
			(d%2==0?es:os).push_back(d);
		rep(i,es.size()){
			int j=lower_bound(all(os),es[i])-begin(os)-1;
			if(0<=j&&es[i]-os[j]<=max(u,v)&&max(u,v)<=es[i]+os[j]) return 2;
		}
		rep(i,os.size()){
			int j=lower_bound(all(es),os[i])-begin(es)-1;
			if(0<=j&&os[i]-es[j]<=max(u,v)&&max(u,v)<=os[i]+es[j]) return 2;
		}
	}
	return -1;
}

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n;cin>>n&&n;){
		vl ds(n);
		rep(i,n) cin>>ds[i];
		ll x,y; cin>>x>>y;
		cout<<solve(ds,x,y)<<endl;
	}
}
0