結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー hatoohatoo
提出日時 2017-10-13 22:23:08
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 3,230 bytes
コンパイル時間 12,916 ms
コンパイル使用メモリ 387,564 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-28 17:35:25
合計ジャッジ時間 14,530 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 res = scores.binary_search_by_key(&(n - m + 1), |&buddy| n - rank(k, buddy, &a));
    match res {
        Ok(i) => {
            println!("{}", scores[i]);
        }
        Err(i) => {
            if i == scores.len() {
                println!("-1");
            } else {
                println!("{}", scores[i]);
            }
        }
    }
}
0