結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 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,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 18 ms
4,380 KB
testcase_19 WA -
testcase_20 AC 29 ms
4,380 KB
testcase_21 AC 22 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 24 ms
4,384 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++) {
    int low = i + 1, high = n;
    while (high - low > 5) {
      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;
      }
    }
  }
  // 遠くに行って戻ってくる
  reverse(d, d + n);
  for (int i = 0; i < n; i++) {
    int low = i + 1, high = n;
    while (high - low > 5) {
      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