結果

問題 No.602 隠されていたゲーム2
ユーザー te-shte-sh
提出日時 2017-12-02 01:03:05
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,185 bytes
コンパイル時間 828 ms
コンパイル使用メモリ 102,008 KB
実行使用メモリ 6,384 KB
最終ジャッジ日時 2023-09-03 17:10:14
合計ジャッジ時間 2,159 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 15 ms
4,376 KB
testcase_18 AC 37 ms
5,616 KB
testcase_19 AC 45 ms
6,384 KB
testcase_20 AC 35 ms
6,348 KB
testcase_21 AC 28 ms
5,696 KB
testcase_22 AC 50 ms
6,120 KB
testcase_23 AC 24 ms
6,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.math;      // math functions

void main()
{
  auto n = readln.chomp.to!int;
  auto d = readln.split.to!(int[]);
  auto rd = readln.split.to!(int[]), x = rd[0].abs, y = rd[1].abs, d1 = x + y;

  if (d1 == 0) {
    writeln(0);
    return;
  }

  auto ds = d.sort();

  if (ds.contains(d1)) {
    writeln(1);
    return;
  }

  auto o = ds.filter!"a&1".array.assumeSorted!"a < b";
  auto e = ds.filter!"!(a&1)".array.assumeSorted!"a < b";

  if (d1&1) {
    foreach (oi; o) {
      auto es = e.lowerBound(oi).upperBound((d1-oi).abs-1);
      if (!es.empty) {
        writeln(2);
        return;
      }
    }
    foreach (ei; e) {
      auto os = o.lowerBound(ei).upperBound((d1-ei).abs-1);
      if (!os.empty) {
        writeln(2);
        return;
      }
    }
  } else {
    foreach (ei; e) {
      auto es = e.lowerBound(ei+1).upperBound((d1-ei).abs-1);
      if (!es.empty) {
        writeln(2);
        return;
      }
    }
    foreach (oi; o) {
      auto os = o.lowerBound(oi+1).upperBound((d1-oi).abs-1);
      if (!os.empty) {
        writeln(2);
        return;
      }
    }
  }

  writeln(-1);
}
0