結果

問題 No.1 道のショートカット
ユーザー qryxipqryxip
提出日時 2018-06-17 17:06:09
言語 Rust
(1.77.0)
結果
MLE  
実行時間 -
コード長 4,124 bytes
コンパイル時間 4,657 ms
コンパイル使用メモリ 149,072 KB
実行使用メモリ 813,084 KB
最終ジャッジ日時 2023-09-22 13:20:22
合計ジャッジ時間 8,012 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 286 ms
32,932 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 MLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
#![cfg_attr(feature = "cargo-clippy", allow(redundant_field_names))]

use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, BufWriter, Read, Write};
use std::ops::{Add, Div, Mul, Sub};
use std::str::{self, FromStr};
use std::{cmp, fmt};

fn main() {
    let (n, c, ss, ts, ys, ms): (usize, u32, Vec<usize>, Vec<usize>, Vec<u32>, Vec<u32>) = {
        let mut sc = InputScanOnce::new(io::stdin(), 1024);
        let (n, c, v) = (sc.next(), sc.next(), sc.next());
        (n, c, sc.vec(v), sc.vec(v), sc.vec(v), sc.vec(v))
    };
    let g = {
        let mut g = vec![vec![]; n];
        for (((s, t), y), m) in ss.into_iter().zip(ts).zip(ys).zip(ms) {
            g[s - 1].push(E { t: t - 1, y, m });
        }
        g
    };
    let mut vs = vec![V { s: 0, y: 0, m: 0 }];
    let mut os: Vec<Option<O>> = vec![None; n];
    let mut r = None;
    while !vs.is_empty() {
        let mut vs_ = vec![];
        for v in vs {
            for e in &g[v.s] {
                let v = V {
                    s: e.t,
                    y: v.y + e.y,
                    m: v.m + e.m,
                };
                if v.y <= c {
                    if v.s == n - 1 {
                        r = Some(match r {
                            None => v.m,
                            Some(r) => cmp::min(r, v.m),
                        });
                    } else {
                        match os[v.s] {
                            Some(o) if o.y <= v.y && o.m <= v.m => {}
                            _ => {
                                os[v.s] = Some(O { y: v.y, m: v.m });
                                vs_.push(v)
                            }
                        }
                    }
                }
            }
        }
        vs = vs_;
    }
    match r {
        None => println!("-1"),
        Some(r) => println!("{}", r),
    }
}

#[derive(Clone, Copy)]
struct E {
    t: usize,
    y: u32,
    m: u32,
}

struct V {
    s: usize,
    y: u32,
    m: u32,
}

#[derive(Clone, Copy)]
struct O {
    y: u32,
    m: u32,
}

struct InputScanOnce {
    buf: Vec<u8>,
    pos: usize,
}

#[allow(dead_code)]
impl InputScanOnce {
    fn new<R: Read>(mut reader: R, estimated: usize) -> Self {
        let mut buf = Vec::with_capacity(estimated);
        let _ = io::copy(&mut reader, &mut buf).unwrap();
        InputScanOnce { buf: buf, pos: 0 }
    }

    #[inline]
    fn next<T: FromStr>(&mut self) -> T
    where
        T::Err: fmt::Debug,
    {
        let mut start = None;
        loop {
            match (self.buf[self.pos], start.is_some()) {
                (b' ', true) | (b'\n', true) => break,
                (_, true) | (b' ', false) | (b'\n', false) => self.pos += 1,
                (_, false) => start = Some(self.pos),
            }
        }
        let target = &self.buf[start.unwrap()..self.pos];
        unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        T::Err: fmt::Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<T1: FromStr, T2: FromStr>(&mut self, n: usize) -> Vec<(T1, T2)>
    where
        T1::Err: fmt::Debug,
        T2::Err: fmt::Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<T1: FromStr, T2: FromStr, T3: FromStr>(&mut self, n: usize) -> Vec<(T1, T2, T3)>
    where
        T1::Err: fmt::Debug,
        T2::Err: fmt::Debug,
        T3::Err: fmt::Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        T::Err: fmt::Debug,
    {
        (0..m).map(|_| self.vec(n)).collect()
    }

    fn strings_as_mat<T, F: FnMut(u8) -> T>(&mut self, h: usize, mut f: F) -> Vec<Vec<T>> {
        (0..h)
            .map(|_| {
                let l = self.next::<String>();
                l.as_bytes().iter().cloned().map(&mut f).collect()
            })
            .collect()
    }
}
0