結果

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

テストケース

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

ソースコード

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;
      }
    }
  }
  cout << -1 << endl;
}
0