結果

問題 No.602 隠されていたゲーム2
ユーザー sekiya9311sekiya9311
提出日時 2017-12-02 02:35:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,620 bytes
コンパイル時間 1,621 ms
コンパイル使用メモリ 171,032 KB
実行使用メモリ 4,996 KB
最終ジャッジ日時 2023-08-18 19:05:06
合計ジャッジ時間 2,797 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int MAX = 1e5 + 10;
int n;
long long d[MAX];
long long x, y;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", d + i);
  }
  scanf("%lld%lld", &x, &y);
  sort(d, d + n);
  if (x == 0 && y == 0) {
    cout << 0 << endl;
    return 0;
  }
  x = llabs(x);
  y = llabs(y);
  for (int i = 0; i < n; i++) {
    if (d[i] == x + y) {
      cout << 1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (d[i] * 2 == x + y) {
      cout << 2 << endl;
      return 0;
    }
  }
  // 前進前進
  for (int i = 0; i < n; i++) {
    int low = 0, high = n - 1;
    while (high - low > 10) {
      int mid = (high + low) / 2;
      if (d[i] + d[mid] < x + y) {
        low = mid;
      } else {
        high = mid;
      }
    }
    for (int j = low; j <= high; j++) {
      if (d[i] + d[j] == x + y) {
        cout << 2 << endl;
        return 0;
      }
    }
  }
  // 遠くに行って戻ってくる
  for (int i = 0; i < n; i++) {
    int low = 0, high = n - 1;
    while (high - low > 10) {
      int mid = (high + low) / 2;
      if (d[i] - d[mid] < x + y) {
        high = mid;
      } else {
        low = mid;
      }
    }
    for (int j = low; j <= high; j++) {
      if (d[i] - d[j] == x + y) {
        cout << 2 << endl;
        return 0;
      }
    }
  }

  vector<long long> v[2];
  for (int i = 0; i < n; i++) {
    v[d[i] % 2].emplace_back(d[i]);
  }
  for (int i = 0; i < n; i++) {
    if (d[i] + v[d[i] % 2].back() >= x + y) {
      cout << 2 << endl;
      return 0;
    }
  }

  cout << -1 << endl;
}
0