結果

問題 No.602 隠されていたゲーム2
ユーザー hatoohatoo
提出日時 2017-12-03 13:05:04
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,907 bytes
コンパイル時間 1,176 ms
コンパイル使用メモリ 145,184 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 22:46:30
合計ジャッジ時間 2,040 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,384 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,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 8 ms
4,380 KB
testcase_19 AC 10 ms
4,380 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 10 ms
4,376 KB
testcase_23 AC 8 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
  --> Main.rs:83:9
   |
83 |     let n = get!(usize);
   |         ^ help: if this is intentional, prefix it with an underscore: `_n`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n = get!(usize);
    let ds = get!(i64;;);
    let (x, y) = get!(i64, i64);

    let mut heaps = vec![BinaryHeap::new(); 2];

    for &d in &ds {
        heaps[(d % 2) as usize].push(d);
    }

    let z = x.abs() + y.abs();

    if z == 0 {
        println!("0");
        return;
    }

    if ds.iter().any(|&d| d == z) {
        println!("1");
        return;
    }


    if z % 2 == 0 {
        if (heaps[0].pop().unwrap_or(0) * 2 >= z) || (heaps[1].pop().unwrap_or(0) * 2 >= z) {
            println!("2");
        } else {
            println!("-1");
        }
    } else {
        if heaps[0].len() >= 1 && heaps[1].len() >= 1 &&
            heaps[0].pop().unwrap_or(0) + heaps[1].pop().unwrap_or(0) >= z
        {
            println!("2");
        } else {
            println!("-1");
        }
    }
}
0