結果
問題 | No.602 隠されていたゲーム2 |
ユーザー |
|
提出日時 | 2017-12-02 00:59:23 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 1,788 bytes |
コンパイル時間 | 775 ms |
コンパイル使用メモリ | 113,808 KB |
実行使用メモリ | 6,308 KB |
最終ジャッジ日時 | 2024-06-12 22:45:56 |
合計ジャッジ時間 | 1,808 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;import std.range, std.array, std.math, std.typecons, std.container, core.bitop;void main() {int n;scan(n);auto d = readln.split.to!(int[]);int x, y;scan(x, y);long L = abs(x) + abs(y);if (L == 0) {writeln(0);return;}foreach (i ; 0 .. n) {if (d[i] == L) {writeln(1);return;}}d.sort();auto ev = new int[](0);auto od = new int[](0);foreach (i ; 0 .. n) {if (d[i] & 1) od ~= d[i];else ev ~= d[i];}debug {writeln(ev);writeln(od);}foreach (i ; 0 .. n) {long ue = L + d[i], sita;if (d[i] <= L) {sita = L - d[i];}else {sita = d[i] - L;}if (ue & 1) {auto seg = od.assumeSorted.lowerBound(ue + 1);auto segs = seg.assumeSorted.upperBound(sita -1);if (!segs.empty) {writeln(2);return;}}else {auto seg = ev.assumeSorted.lowerBound(ue+1);auto segs = seg.assumeSorted.upperBound(sita-1);if (!segs.empty) {writeln(2);return;}}}writeln(-1);}void scan(T...)(ref T args) {string[] line = readln.split;foreach (ref arg; args) {arg = line.front.to!(typeof(arg));line.popFront();}assert(line.empty);}void fillAll(R, T)(ref R arr, T value) {static if (is(typeof(arr[] = value))) {arr[] = value;}else {foreach (ref e; arr) {fillAll(e, value);}}}