結果

問題 No.1703 Much Matching
ユーザー akakimidoriakakimidori
提出日時 2021-10-09 05:24:27
言語 Rust
(1.77.0)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 3,753 bytes
コンパイル時間 1,135 ms
コンパイル使用メモリ 155,388 KB
実行使用メモリ 32,124 KB
最終ジャッジ日時 2023-09-30 22:10:20
合計ジャッジ時間 4,707 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 64 ms
9,904 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 74 ms
12,208 KB
testcase_09 AC 86 ms
13,764 KB
testcase_10 AC 11 ms
4,380 KB
testcase_11 AC 18 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 33 ms
5,508 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 15 ms
4,380 KB
testcase_16 AC 42 ms
8,060 KB
testcase_17 AC 53 ms
8,408 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 109 ms
15,556 KB
testcase_20 AC 12 ms
4,380 KB
testcase_21 AC 134 ms
17,020 KB
testcase_22 AC 50 ms
8,320 KB
testcase_23 AC 40 ms
7,360 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 24 ms
4,996 KB
testcase_27 AC 57 ms
8,660 KB
testcase_28 AC 111 ms
15,048 KB
testcase_29 AC 20 ms
4,720 KB
testcase_30 AC 30 ms
5,504 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 55 ms
8,808 KB
testcase_33 AC 37 ms
7,188 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 10 ms
4,376 KB
testcase_36 AC 254 ms
32,124 KB
testcase_37 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// ---------- begin super slice ----------
pub trait SuperSlice {
    type Item;
    fn lower_bound(&self, key: &Self::Item) -> usize
    where
        Self::Item: Ord;
    fn lower_bound_by<F>(&self, f: F) -> usize
    where
        F: FnMut(&Self::Item) -> std::cmp::Ordering;
    fn lower_bound_by_key<K, F>(&self, key: &K, f: F) -> usize
    where
        K: Ord,
        F: FnMut(&Self::Item) -> K;
    fn upper_bound(&self, key: &Self::Item) -> usize
    where
        Self::Item: Ord;
    fn upper_bound_by<F>(&self, f: F) -> usize
    where
        F: FnMut(&Self::Item) -> std::cmp::Ordering;
    fn upper_bound_by_key<K, F>(&self, key: &K, f: F) -> usize
    where
        K: Ord,
        F: FnMut(&Self::Item) -> K;
}

impl<T> SuperSlice for [T] {
    type Item = T;
    fn lower_bound(&self, key: &Self::Item) -> usize
    where
        T: Ord,
    {
        self.lower_bound_by(|p| p.cmp(key))
    }
    fn lower_bound_by<F>(&self, mut f: F) -> usize
    where
        F: FnMut(&Self::Item) -> std::cmp::Ordering,
    {
        self.binary_search_by(|p| f(p).then(std::cmp::Ordering::Greater))
            .unwrap_err()
    }
    fn lower_bound_by_key<K, F>(&self, key: &K, mut f: F) -> usize
    where
        K: Ord,
        F: FnMut(&Self::Item) -> K,
    {
        self.lower_bound_by(|p| f(p).cmp(key))
    }
    fn upper_bound(&self, key: &Self::Item) -> usize
    where
        T: Ord,
    {
        self.upper_bound_by(|p| p.cmp(key))
    }
    fn upper_bound_by<F>(&self, mut f: F) -> usize
    where
        F: FnMut(&Self::Item) -> std::cmp::Ordering,
    {
        self.binary_search_by(|p| f(p).then(std::cmp::Ordering::Less))
            .unwrap_err()
    }
    fn upper_bound_by_key<K, F>(&self, key: &K, mut f: F) -> usize
    where
        K: Ord,
        F: FnMut(&Self::Item) -> K,
    {
        self.upper_bound_by(|p| f(p).cmp(key))
    }
}
// ---------- end super slice ----------
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

fn run() {
    input! {
        n: usize,
        m: usize,
        q: usize,
        p: [(usize, usize); q],
    }
    let mut p = p;
    p.sort_by_key(|p| (p.0, !p.1));
    let mut dp = vec![m + 1; n + 1];
    dp[0] = 0;
    for (_, b) in p {
        let x = dp.lower_bound(&b);
        dp[x] = b;
    }
    let ans = dp.iter().rposition(|dp| *dp < m + 1).unwrap();
    println!("{}", ans);
}

fn main() {
    run();
}
0