結果

問題 No.1607 Kth Maximum Card
ユーザー akakimidoriakakimidori
提出日時 2021-07-16 21:55:03
言語 Rust
(1.72.1)
結果
AC  
実行時間 2,271 ms / 3,500 ms
コード長 3,132 bytes
コンパイル時間 1,898 ms
コンパイル使用メモリ 155,496 KB
実行使用メモリ 32,068 KB
最終ジャッジ日時 2023-09-20 13:46:34
合計ジャッジ時間 24,478 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 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,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1,957 ms
31,824 KB
testcase_09 AC 1,443 ms
27,292 KB
testcase_10 AC 2,080 ms
32,068 KB
testcase_11 AC 147 ms
9,208 KB
testcase_12 AC 1,418 ms
26,420 KB
testcase_13 AC 85 ms
6,532 KB
testcase_14 AC 107 ms
7,900 KB
testcase_15 AC 1,068 ms
24,788 KB
testcase_16 AC 83 ms
6,872 KB
testcase_17 AC 26 ms
4,380 KB
testcase_18 AC 449 ms
18,720 KB
testcase_19 AC 196 ms
11,856 KB
testcase_20 AC 333 ms
13,916 KB
testcase_21 AC 425 ms
17,112 KB
testcase_22 AC 2,088 ms
31,724 KB
testcase_23 AC 2,026 ms
31,684 KB
testcase_24 AC 269 ms
12,288 KB
testcase_25 AC 133 ms
8,196 KB
testcase_26 AC 180 ms
9,132 KB
testcase_27 AC 324 ms
12,580 KB
testcase_28 AC 224 ms
10,080 KB
testcase_29 AC 914 ms
21,336 KB
testcase_30 AC 2,271 ms
31,260 KB
testcase_31 AC 755 ms
17,864 KB
testcase_32 AC 225 ms
21,764 KB
testcase_33 AC 233 ms
21,636 KB
testcase_34 AC 235 ms
21,672 KB
testcase_35 AC 232 ms
21,796 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::io::Write`
  --> Main.rs:72:5
   |
72 | use std::io::Write;
   |     ^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: type alias `Map` is never used
  --> Main.rs:75:6
   |
75 | type Map<K, V> = BTreeMap<K, V>;
   |      ^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: type alias `Set` is never used
  --> Main.rs:76:6
   |
76 | type Set<T> = BTreeSet<T>;
   |      ^^^

warning: 3 warnings emitted

ソースコード

diff #

// ---------- begin chmin, chmax ----------
pub trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------
// ---------- 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 ----------

use std::io::Write;
use std::collections::*;

type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;

fn run() {
    input! {
        n: usize,
        m: usize,
        k: u32,
        e: [(usize1, usize1, u32); m],
    }
    let valid = |m: u32| -> bool {
        let mut g = vec![vec![]; n];
        for &(a, b, c) in e.iter() {
            let c = if c >= m {1} else {0};
            g[a].push((b, c));
            g[b].push((a, c));
        }
        let mut dp = vec![k + 1; n];
        dp[0] = 0;
        let mut deq = Deque::new();
        deq.push_back(0);
        while let Some(v) = deq.pop_front() {
            let d = dp[v];
            for &(u, c) in g[v].iter() {
                if c == 0 && dp[u].chmin(d) {
                    deq.push_front(u);
                }
                if c == 1 && dp[u].chmin(d + 1) {
                    deq.push_back(u);
                }
            }
        }
        dp[n - 1] < k
    };
    let mut ng = 0;
    let mut ok = 200001;
    while ok - ng > 1 {
        let mid = (ok + ng) / 2;
        if valid(mid) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    println!("{}", ng);
}

fn main() {
    run();
}
0