結果

問題 No.602 隠されていたゲーム2
ユーザー pekempeypekempey
提出日時 2017-12-02 00:44:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,427 bytes
コンパイル時間 946 ms
コンパイル使用メモリ 76,708 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-09 11:28:46
合計ジャッジ時間 1,928 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 9 ms
5,376 KB
testcase_17 AC 17 ms
5,376 KB
testcase_18 AC 41 ms
5,376 KB
testcase_19 AC 50 ms
5,376 KB
testcase_20 AC 44 ms
5,376 KB
testcase_21 AC 39 ms
5,376 KB
testcase_22 AC 44 ms
5,376 KB
testcase_23 AC 46 ms
5,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