結果

問題 No.1449 新プロランド
ユーザー RheoTommyRheoTommy
提出日時 2021-03-31 19:33:03
言語 Rust
(1.77.0)
結果
AC  
実行時間 1,284 ms / 2,000 ms
コード長 3,886 bytes
コンパイル時間 1,251 ms
コンパイル使用メモリ 157,252 KB
実行使用メモリ 72,804 KB
最終ジャッジ日時 2023-08-25 16:50:31
合計ジャッジ時間 11,903 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,380 KB
testcase_01 AC 17 ms
5,028 KB
testcase_02 AC 59 ms
6,712 KB
testcase_03 AC 6 ms
5,076 KB
testcase_04 AC 9 ms
5,104 KB
testcase_05 AC 1,284 ms
68,872 KB
testcase_06 AC 657 ms
46,136 KB
testcase_07 AC 342 ms
48,164 KB
testcase_08 AC 805 ms
72,804 KB
testcase_09 AC 256 ms
16,204 KB
testcase_10 AC 335 ms
61,564 KB
testcase_11 AC 97 ms
68,460 KB
testcase_12 AC 818 ms
61,072 KB
testcase_13 AC 312 ms
24,932 KB
testcase_14 AC 119 ms
71,596 KB
testcase_15 AC 804 ms
52,436 KB
testcase_16 AC 487 ms
30,312 KB
testcase_17 AC 539 ms
44,464 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 39 ms
53,688 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 193 ms
48,136 KB
testcase_22 AC 53 ms
7,476 KB
testcase_23 AC 260 ms
66,344 KB
testcase_24 AC 180 ms
13,864 KB
testcase_25 AC 123 ms
11,448 KB
testcase_26 AC 11 ms
4,376 KB
testcase_27 AC 1,203 ms
72,032 KB
testcase_28 AC 484 ms
26,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

// # ファイル構成
// - use 宣言
// - lib モジュール
// - main 関数
// - basic モジュール
//
// 常に使うテンプレートライブラリは basic モジュール内にあります。
// 問題に応じて使うライブラリ lib モジュール内にコピペしています。
// ライブラリのコードはこちら → https://github.com/RheoTommy/at_coder
// Twitter はこちら → https://twitter.com/RheoTommy

use std::collections::*;
use std::io::{stdout, BufWriter, Write};

use crate::basic::*;
use crate::lib::*;

pub mod lib {}

fn main() {
    let mut sc = Scanner::new();

    let n = sc.next_usize();
    let m = sc.next_usize();
    let mut vertex = vec![vec![]; n];
    for _ in 0..m {
        let a = sc.next_usize() - 1;
        let b = sc.next_usize() - 1;
        let c = sc.next_usize();
        vertex[a].push((b, c));
        vertex[b].push((a, c));
    }
    let t = sc.next_vec::<usize>(n);

    let mut dp = vec![vec![U_INF as usize; 100001]; n];
    dp[0][0] = 0;
    let mut heap = BinaryHeap::new();
    heap.push((U_INF as usize, 0, 0, 0));
    while let Some((_, time, u, p)) = heap.pop() {
        // eprintln!("{:?}", (time, u, p));
        if dp[u][p] < time {
            continue;
        }
        let p = p + t[u];
        let time = time + t[u];

        for &(v, cost) in &vertex[u] {
            let next_time = time + cost / p;
            if p <= 100000 && dp[v][p] > next_time {
                dp[v][p] = next_time;
                heap.push((U_INF as usize - next_time, next_time, v, p));
            }
        }
    }

    println!("{}", dp[n - 1].iter().min().unwrap());
}

pub mod basic {
    pub const U_INF: u64 = (1 << 60) + (1 << 30);
    pub const I_INF: i64 = (1 << 60) + (1 << 30);

    pub struct Scanner {
        buf: std::collections::VecDeque<String>,
        reader: std::io::BufReader<std::io::Stdin>,
    }

    impl Scanner {
        pub fn new() -> Self {
            Self {
                buf: std::collections::VecDeque::new(),
                reader: std::io::BufReader::new(std::io::stdin()),
            }
        }

        fn scan_line(&mut self) {
            use std::io::BufRead;
            let mut flag = 0;
            while self.buf.is_empty() {
                let mut s = String::new();
                self.reader.read_line(&mut s).unwrap();
                let mut iter = s.split_whitespace().peekable();
                if iter.peek().is_none() {
                    if flag >= 5 {
                        panic!("There is no input!");
                    }
                    flag += 1;
                    continue;
                }

                for si in iter {
                    self.buf.push_back(si.to_string());
                }
            }
        }

        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            self.scan_line();
            self.buf
                .pop_front()
                .unwrap()
                .parse()
                .unwrap_or_else(|_| panic!("Couldn't parse!"))
        }

        pub fn next_usize(&mut self) -> usize {
            self.next()
        }

        pub fn next_int(&mut self) -> i64 {
            self.next()
        }

        pub fn next_uint(&mut self) -> u64 {
            self.next()
        }

        pub fn next_chars(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_string(&mut self) -> String {
            self.next()
        }

        pub fn next_char(&mut self) -> char {
            self.next()
        }

        pub fn next_float(&mut self) -> f64 {
            self.next()
        }

        pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect::<Vec<_>>()
        }
    }
}
0