結果

問題 No.602 隠されていたゲーム2
ユーザー tnakao0123tnakao0123
提出日時 2017-12-03 01:32:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 2,023 bytes
コンパイル時間 658 ms
コンパイル使用メモリ 87,684 KB
実行使用メモリ 4,456 KB
最終ジャッジ日時 2023-08-22 05:39:05
合計ジャッジ時間 1,981 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 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,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 18 ms
4,384 KB
testcase_19 AC 22 ms
4,384 KB
testcase_20 AC 23 ms
4,376 KB
testcase_21 AC 15 ms
4,456 KB
testcase_22 AC 25 ms
4,384 KB
testcase_23 AC 16 ms
4,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- 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;
}
0