結果

問題 No.2739 Time is money
ユーザー 👑 tipstar0125tipstar0125
提出日時 2024-04-20 17:10:12
言語 Rust
(1.77.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 1,991 bytes
コンパイル時間 2,391 ms
コンパイル使用メモリ 173,184 KB
実行使用メモリ 42,020 KB
最終ジャッジ日時 2024-04-20 17:10:19
合計ジャッジ時間 6,255 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 52 ms
24,960 KB
testcase_03 AC 130 ms
31,872 KB
testcase_04 AC 48 ms
23,936 KB
testcase_05 AC 102 ms
23,384 KB
testcase_06 AC 93 ms
29,056 KB
testcase_07 AC 183 ms
42,020 KB
testcase_08 AC 161 ms
41,728 KB
testcase_09 AC 167 ms
40,988 KB
testcase_10 AC 103 ms
40,704 KB
testcase_11 AC 185 ms
41,116 KB
testcase_12 AC 116 ms
41,344 KB
testcase_13 AC 138 ms
41,396 KB
testcase_14 AC 113 ms
40,564 KB
testcase_15 AC 64 ms
33,280 KB
testcase_16 AC 71 ms
31,872 KB
testcase_17 AC 164 ms
39,404 KB
testcase_18 AC 155 ms
40,328 KB
testcase_19 AC 91 ms
33,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(clippy::needless_range_loop)]
#![allow(clippy::comparison_chain)]
#![allow(clippy::nonminimal_bool)]
#![allow(clippy::neg_multiply)]
#![allow(dead_code)]
// use itertools::Itertools;
use std::cmp::Reverse;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};
// use superslice::Ext;
// use bitset_fixed::BitSet;

use proconio::{
    input,
    marker::{Chars, Usize1},
};

#[derive(Default)]
struct Solver {}
impl Solver {
    // #[fastout]
    fn solve(&mut self) {
        input! {
            N: usize,
            M: usize,
            X: usize,
            UVCT: [(Usize1, Usize1, usize, usize); M]
        }

        let mut G = vec![vec![]; N];
        for &(u, v, c, t) in UVCT.iter() {
            G[u].push((v, c, t));
            G[v].push((u, c, t));
        }

        let INF = 1_usize << 60;
        let mut dist = vec![INF; N];
        dist[0] = 0;
        let mut Q = BinaryHeap::new();
        Q.push((Reverse(0), 0, 0));
        while let Some((Reverse(d), pos, money)) = Q.pop() {
            if dist[pos] != d {
                continue;
            }
            for &(nxt, c, t) in &G[pos] {
                let tt = if c <= money {
                    0
                } else {
                    (c - money + X - 1) / X
                };
                let dd = t + tt;
                let next_money = tt * X + money - c;
                if dist[pos] + dd < dist[nxt] {
                    dist[nxt] = dist[pos] + dd;
                    Q.push((Reverse(dist[nxt]), nxt, next_money));
                }
            }
        }
        let ans = dist[N - 1];
        if ans == INF {
            println!("-1");
        } else {
            println!("{}", ans);
        }
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(128 * 1024 * 1024)
        .spawn(|| Solver::default().solve())
        .unwrap()
        .join()
        .unwrap();
}
0