結果
問題 |
No.602 隠されていたゲーム2
|
ユーザー |
![]() |
提出日時 | 2019-07-07 19:19:08 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 47 ms / 2,000 ms |
コード長 | 1,486 bytes |
コンパイル時間 | 753 ms |
コンパイル使用メモリ | 103,644 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-05 06:03:29 |
合計ジャッジ時間 | 1,781 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair<int, int> P; int main() { int n; ll x, y; cin>>n; ll d[100010]; vector<ll> d0, d1; for(int i=0; i<n; i++){ cin>>d[i]; if(d[i]&1) d1.push_back(d[i]); else d0.push_back(d[i]); } cin>>x>>y; ll s=abs(x)+abs(y); if(s==0){ cout<<0<<endl; return 0; } for(int i=0; i<n; i++){ if(s==d[i]){ cout<<1<<endl; return 0; } } sort(d0.begin(), d0.end()); sort(d1.begin(), d1.end()); ll mx0=(d0.empty() ? 0 : d0.back()); ll mx1=(d1.empty() ? 0 : d1.back()); if(s%2==0){ if(s<=2*max(mx0, mx1)) cout<<2<<endl; else cout<<-1<<endl; }else{ if(d0.empty() || d1.empty()){ cout<<-1<<endl; return 0; } for(auto a:d0){ int i=lower_bound(d1.begin(), d1.end(), abs(a-s))-d1.begin(); if(i<d1.size() && d1[i]<=a+s){ cout<<2<<endl; return 0; } } cout<<-1<<endl; } return 0; }