結果

問題 No.1557 Binary Variable
コンテスト
ユーザー fukafukatani
提出日時 2021-06-25 21:37:30
言語 Rust
(1.93.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,133 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,109 ms
コンパイル使用メモリ 200,760 KB
実行使用メモリ 8,376 KB
最終ジャッジ日時 2026-03-11 17:05:53
合計ジャッジ時間 3,591 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (n, m) = (v[0], v[1] as usize);
    let mut spans = (0..m)
        .map(|_| {
            let v = read_vec::<i64>();
            (v[0], v[1])
        })
        .collect::<Vec<_>>();
    spans.sort_by_key(|&x| x.1);

    let mut cur = 0;
    let mut ans = 0;
    for (l, r) in spans {
        if cur < l {
            ans += 1;
            cur = r;
        }
    }
    println!("{}", n - ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0