結果

問題 No.564 背の順
ユーザー ikdikd
提出日時 2020-07-25 23:31:37
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 2,872 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 152,060 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 02:10:54
合計ジャッジ時間 1,710 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn read<T: std::str::FromStr>() -> T {
    let token: String = std::io::stdin()
        .bytes()
        .map(|c| c.ok().unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

mod binary_search {
    use std::cmp::Ordering::{Equal, Greater, Less};
    use std::ops::Range;
    pub trait BinarySearch<T> {
        fn lower_bound(&self, x: &T) -> usize;
        fn upper_bound(&self, x: &T) -> usize;
        fn split_by(&self, x: &T) -> (Range<usize>, Range<usize>, Range<usize>);
    }

    // min index self[i] >= x
    // that is, any j (j < i) holds self[j] < x
    impl<T: Ord> BinarySearch<T> for [T] {
        fn lower_bound(&self, x: &T) -> usize {
            match self[0].cmp(x) {
                Greater | Equal => {
                    return 0;
                }
                _ => (),
            }
            let mut lf = 0;
            let mut rg = self.len();
            // self[lf] < x
            while rg - lf > 1 {
                let md = (rg + lf) / 2;
                match self[md].cmp(x) {
                    Less => {
                        lf = md;
                    }
                    Greater | Equal => {
                        rg = md;
                    }
                }
            }
            rg
        }

        // min index self[i] > x
        // that is, any j (j < i) holds self[j] <= x
        fn upper_bound(&self, x: &T) -> usize {
            match self[0].cmp(x) {
                Greater => {
                    return 0;
                }
                _ => (),
            }
            let mut lf = 0;
            let mut rg = self.len();
            // self[lf] <= x
            while rg - lf > 1 {
                let md = (rg + lf) / 2;
                match self[md].cmp(x) {
                    Less | Equal => {
                        lf = md;
                    }
                    Greater => {
                        rg = md;
                    }
                }
            }
            rg
        }

        fn split_by(&self, x: &T) -> (Range<usize>, Range<usize>, Range<usize>) {
            let i = self.lower_bound(x);
            let j = self.upper_bound(x);
            (0..i, i..j, j..self.len())
        }
    }
}

use binary_search::BinarySearch;

fn main() {
    let h: i32 = read();
    let n: usize = read();
    let mut a = vec![0; n - 1];
    for i in 0..n - 1 {
        a[i] = read();
    }
    a.sort();
    let (_, _, r) = a.split_by(&h);
    let o = r.len() + 1;
    println!(
        "{}",
        if o % 10 == 1 {
            format!("{}st", o)
        } else if o % 10 == 2 {
            format!("{}nd", o)
        } else if o % 10 == 3 {
            format!("{}rd", o)
        } else {
            format!("{}th", o)
        }
    );
}
0