結果

問題 No.602 隠されていたゲーム2
ユーザー kzyKT
提出日時 2017-10-30 10:08:17
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 514 bytes
コンパイル時間 2,313 ms
コンパイル使用メモリ 162,148 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-15 23:55:50
合計ジャッジ時間 3,047 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,d[111111];

ll solve(ll x) {
  sort(d,d+n);
  if(!x) return 0;
  for(ll i=0; i<n; i++) {
    if(x==d[i]) return 1;
  }
  ll o=0,e=0;
  for(ll i=0; i<n; i++) {
    if(d[i]%2) o=d[i];
    else e=d[i];
    if(x%2&&abs(o-e)<=x&&x<=o+e) return 2;
  }
  if(x%2==0&&x<=d[n-1]*2) return 2;
  return -1;
}

int main() {
  ll x,y;
  cin >> n;
  for(ll i=0; i<n; i++) cin >> d[i];
  cin >> x >> y;
  cout << solve(abs(x)+abs(y)) << endl;
  return 0;
}
0