結果
問題 | No.507 ゲーム大会(チーム決め) |
ユーザー | hatoo |
提出日時 | 2017-10-13 23:12:57 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 25 ms / 3,000 ms |
コード長 | 3,449 bytes |
コンパイル時間 | 18,748 ms |
コンパイル使用メモリ | 390,000 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-17 11:45:57 |
合計ジャッジ時間 | 20,820 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 0 ms
6,820 KB |
testcase_04 | AC | 1 ms
6,820 KB |
testcase_05 | AC | 1 ms
6,816 KB |
testcase_06 | AC | 1 ms
6,820 KB |
testcase_07 | AC | 25 ms
6,816 KB |
testcase_08 | AC | 22 ms
6,820 KB |
testcase_09 | AC | 17 ms
6,820 KB |
testcase_10 | AC | 16 ms
6,816 KB |
testcase_11 | AC | 14 ms
6,820 KB |
testcase_12 | AC | 17 ms
6,816 KB |
testcase_13 | AC | 23 ms
6,816 KB |
testcase_14 | AC | 22 ms
6,820 KB |
testcase_15 | AC | 23 ms
6,816 KB |
testcase_16 | AC | 23 ms
6,816 KB |
testcase_17 | AC | 1 ms
6,820 KB |
testcase_18 | AC | 1 ms
6,816 KB |
testcase_19 | AC | 1 ms
6,816 KB |
testcase_20 | AC | 1 ms
6,816 KB |
ソースコード
#[allow(unused_imports)] use std::cmp::{max, min, Ordering}; #[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 bin_search(low: usize, high: usize, a: &[usize], scores: &[usize], k: usize, m: usize) -> i64 { let mid = (low + high) / 2; if low == high { return scores.get(low).cloned().map(|i| i as i64).unwrap_or(-1); } match rank(k, scores[mid], a).cmp(&m) { Ordering::Less => bin_search(low, mid, a, scores, k, m), Ordering::Equal => bin_search(low, mid, a, scores, k, m), Ordering::Greater => bin_search(mid + 1, high, a, scores, k, m), } } 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(); println!("{}", bin_search(0, scores.len(), &a, &scores, k, m - 1)); }