結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー hatoohatoo
提出日時 2017-10-13 22:37:02
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 3,314 bytes
コンパイル時間 12,382 ms
コンパイル使用メモリ 404,080 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-28 17:36:37
合計ジャッジ時間 17,475 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BTreeSet};

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 get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[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(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }

    #[allow(dead_code)]
    pub fn get3<S: FromStr, T: FromStr, U: FromStr>() -> (S, T, U)
    where
        <S as FromStr>::Err: Debug,
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}


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

fn rank(k: usize, buddy: usize, a: &[usize]) -> usize {
    let t = k + buddy;
    let mut l = 0;
    let mut r = a.len() - 1;
    let mut cnt = 0;
    let mut skipped = false;

    while r > l {
        if !skipped && a[l] == buddy {
            l += 1;
            skipped = true;
            continue;
        }
        if !skipped && a[r] == buddy {
            r -= 1;
            skipped = true;
            continue;
        }
        if a[l] + a[r] > t {
            r -= 1;
            l += 1;
            cnt += 1;
        } else {
            l += 1;
        }
    }
    cnt
}

fn main() {
    let (n, m): (usize, usize) = util::get2();
    let k: usize = util::get();
    let mut a: Vec<usize> = (1..n).map(|_| util::get()).collect();

    a.sort();
    let mut scores = a.clone();
    scores.dedup();

    let mut up = scores
        .iter()
        .map(|&s| (n - rank(k, s, &a), s))
        .collect::<Vec<_>>();

    up.sort();

    let res = up.binary_search(&(n - (m - 1), 0));

    match res {
        Ok(i) => {
            println!("{}", up[i].1);
        }
        Err(i) => {
            if i == up.len() {
                println!("-1");
            } else {
                println!("{}", up[i].1);
            }
        }
    }
}
0