結果
問題 |
No.602 隠されていたゲーム2
|
ユーザー |
|
提出日時 | 2017-12-02 00:21:08 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,257 bytes |
コンパイル時間 | 904 ms |
コンパイル使用メモリ | 116,536 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-12 22:45:09 |
合計ジャッジ時間 | 1,739 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 WA * 7 |
ソースコード
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; } d.sort(); foreach (i ; 0 .. n) { if (d[i] == L) { writeln(1); return; } } auto ds = (d.map!(a => -a).retro().array ~ d).assumeSorted(); debug { writeln(ds); } foreach (i ; 0 .. 2*n) { long r = L - ds[i]; auto lb = ds.lowerBound(r + 1); debug { writeln(lb); } if (!lb.empty && lb.back == r) { 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); } } }