結果

問題 No.602 隠されていたゲーム2
ユーザー pekempeypekempey
提出日時 2017-12-02 00:44:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,427 bytes
コンパイル時間 786 ms
コンパイル使用メモリ 77,268 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 05:33:10
合計ジャッジ時間 2,180 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 16 ms
4,376 KB
testcase_18 AC 38 ms
4,380 KB
testcase_19 AC 46 ms
4,380 KB
testcase_20 AC 42 ms
4,380 KB
testcase_21 AC 36 ms
4,376 KB
testcase_22 AC 39 ms
4,376 KB
testcase_23 AC 41 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

  vector<int> d(n);
  vector<int> even, odd;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    if (d[i] % 2 == 0) {
      even.push_back(d[i]);
    } else {
      odd.push_back(d[i]);
    }
  }

  int x, y;
  cin >> x >> y;

  if (x == 0 && y == 0) {
    cout << 0 << endl;
    return 0;
  }

  int dist = abs(x) + abs(y);

  for (int i = 0; i < n; i++) {
    if (dist == d[i]) {
      cout << 1 << endl;
      return 0;
    }
  }

  if (dist % 2 == 0) {
    for (int i = 0; i < n; i++) {
      if (dist <= d[i] * 2) {
        cout << 2 << endl;
        return 0;
      }
    }
    cout << -1 << endl;
    return 0;
  }

  sort(even.begin(), even.end());
  sort(odd.begin(), odd.end());

  for (int i = 0; i < even.size(); i++) {
    auto it = lower_bound(odd.begin(), odd.end(), even[i]);
    if (it != odd.begin()) {
      int j = it - odd.begin() - 1;
      if (even[i] - odd[j] <= dist && dist <= even[i] + odd[j]) {
        cout << 2 << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < odd.size(); i++) {
    auto it = lower_bound(even.begin(), even.end(), odd[i]);
    if (it != even.begin()) {
      int j = it - even.begin() - 1;
      if (odd[i] - even[j] <= dist && dist <= odd[i] + even[j]) {
        cout << 2 << endl;
        return 0;
      }
    }
  }

  cout << -1 << endl;
}
0