結果
| 問題 | No.602 隠されていたゲーム2 | 
| コンテスト | |
| ユーザー |  tnakao0123 | 
| 提出日時 | 2017-12-03 01:32:38 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 25 ms / 2,000 ms | 
| コード長 | 2,023 bytes | 
| コンパイル時間 | 930 ms | 
| コンパイル使用メモリ | 86,844 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-16 00:04:50 | 
| 合計ジャッジ時間 | 1,976 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:50:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   50 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:55:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |     scanf("%lld", &di);
      |     ~~~~~^~~~~~~~~~~~~
main.cpp:62:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   62 |   scanf("%lld%lld", &gx, &gy);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
            
            ソースコード
/* -*- coding: utf-8 -*-
 *
 * 602.cc: No.602 隠されていたゲーム2 - yukicoder
 */
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;
/* constant */
const int MAX_N = 100000;
/* typedef */
typedef long long ll;
/* global variables */
ll eds[MAX_N], ods[MAX_N];
/* subroutines */
bool findg(int n, ll ds[], ll v) {
  int k = lower_bound(ds, ds + n, v) - ds;
  return (k < n && ds[k] == v);
}
/* main */
int main() {
  int n;
  scanf("%d", &n);
  int en = 0, on = 0;
  for (int i = 0; i < n; i++) {
    ll di;
    scanf("%lld", &di);
    if (di & 1) ods[on++] = di;
    else eds[en++] = di;
  }
  //printf("en=%d, on=%d\n", en, on);
  ll gx, gy;
  scanf("%lld%lld", &gx, &gy);
  ll gd = abs(gx) + abs(gy);
  //printf("gd=%d\n", gd);
  if (gd == 0) {
    puts("0");
    return 0;
  }
  sort(eds, eds + en);
  sort(ods, ods + on);
  if (((gd & 1) && findg(on, ods, gd)) ||
      (! (gd & 1) && findg(en, eds, gd))) {
    puts("1");
    return 0;
  }
  if (gd & 1) {
    for (int i = 0; i < en; i++) {
      ll &edi = eds[i];
      int j = lower_bound(ods, ods + on, abs(gd - edi)) - ods;
      int k = upper_bound(ods, ods + on, gd + edi) - ods;
      if (j < k) {
	puts("2");
	return 0;
      }
    }
  }
  else {
    for (int i = 0; i < en; i++) {
      ll &edi = eds[i];
      int j = lower_bound(eds, eds + en, abs(gd - edi)) - eds;
      int k = upper_bound(eds, eds + en, gd + edi) - eds;
      if (j < k) {
	puts("2");
	return 0;
      }
    }
    for (int i = 0; i < on; i++) {
      ll &odi = ods[i];
      int j = lower_bound(ods, ods + on, abs(gd - odi)) - ods;
      int k = upper_bound(ods, ods + on, gd + odi) - ods;
      if (j < k) {
	puts("2");
	return 0;
      }
    }
  }
  
  puts("-1");
  return 0;
}
            
            
            
        