結果

問題 No.602 隠されていたゲーム2
ユーザー koba-e964koba-e964
提出日時 2021-11-05 05:48:17
言語 Rust
(1.77.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 2,650 bytes
コンパイル時間 899 ms
コンパイル使用メモリ 175,680 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 13:26:28
合計ジャッジ時間 1,933 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 6 ms
6,944 KB
testcase_17 AC 12 ms
6,940 KB
testcase_18 AC 15 ms
6,944 KB
testcase_19 AC 19 ms
6,944 KB
testcase_20 AC 18 ms
6,944 KB
testcase_21 AC 12 ms
6,944 KB
testcase_22 AC 24 ms
6,940 KB
testcase_23 AC 12 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

trait Bisect<T> {
    fn lower_bound(&self, val: &T) -> usize;
    fn upper_bound(&self, val: &T) -> usize;
}

impl<T: Ord> Bisect<T> for [T] {
    fn lower_bound(&self, val: &T) -> usize {
        let mut pass = self.len() + 1;
        let mut fail = 0;
        while pass - fail > 1 {
            let mid = (pass + fail) / 2;
            if &self[mid - 1] >= val {
                pass = mid;
            } else {
                fail = mid;
            }
        }
        pass - 1
    }
    fn upper_bound(&self, val: &T) -> usize {
        let mut pass = self.len() + 1;
        let mut fail = 0;
        while pass - fail > 1 {
            let mid = (pass + fail) / 2;
            if &self[mid - 1] > val {
                pass = mid;
            } else {
                fail = mid;
            }
        }
        pass - 1
    }
}

fn main() {
    input! {
        n: usize,
        d: [i64; n],
        x: i64, y: i64,
    }
    let z = x.abs() + y.abs();
    if z == 0 {
        println!("0");
        return;
    }
    for &d in &d {
        if z == d {
            println!("1");
            return;
        }
    }
    let mut deven = vec![];
    let mut dodd = vec![];
    for &d in &d {
        if d % 2 == 0 {
            deven.push(d);
        } else {
            dodd.push(d);
        }
    }
    deven.sort();
    dodd.sort();
    for &d in &d {
        let lo = (d - z).abs();
        let hi = d + z;
        let targ = if hi % 2 == 1 {
            &dodd
        } else {
            &deven
        };
        let lo = targ.lower_bound(&lo);
        let hi = targ.upper_bound(&hi);
        if lo < hi {
            println!("2");
            return;
        }
    }
    println!("-1");
}
0