結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー akakimidoriakakimidori
提出日時 2021-06-11 21:55:33
言語 Rust
(1.77.0)
結果
AC  
実行時間 120 ms / 3,000 ms
コード長 3,256 bytes
コンパイル時間 1,872 ms
コンパイル使用メモリ 154,208 KB
実行使用メモリ 46,828 KB
最終ジャッジ日時 2023-08-21 12:19:16
合計ジャッジ時間 14,055 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 27 ms
17,816 KB
testcase_05 AC 83 ms
33,680 KB
testcase_06 AC 32 ms
14,360 KB
testcase_07 AC 38 ms
19,940 KB
testcase_08 AC 74 ms
16,724 KB
testcase_09 AC 25 ms
12,060 KB
testcase_10 AC 29 ms
16,064 KB
testcase_11 AC 42 ms
19,716 KB
testcase_12 AC 64 ms
27,236 KB
testcase_13 AC 22 ms
11,584 KB
testcase_14 AC 29 ms
17,728 KB
testcase_15 AC 9 ms
5,880 KB
testcase_16 AC 39 ms
24,932 KB
testcase_17 AC 16 ms
7,884 KB
testcase_18 AC 83 ms
26,044 KB
testcase_19 AC 39 ms
16,256 KB
testcase_20 AC 18 ms
7,068 KB
testcase_21 AC 54 ms
31,744 KB
testcase_22 AC 49 ms
25,800 KB
testcase_23 AC 42 ms
15,388 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 4 ms
4,376 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 7 ms
4,376 KB
testcase_36 AC 6 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 4 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 3 ms
4,380 KB
testcase_43 AC 3 ms
4,376 KB
testcase_44 AC 4 ms
4,376 KB
testcase_45 AC 4 ms
4,576 KB
testcase_46 AC 6 ms
4,376 KB
testcase_47 AC 9 ms
5,048 KB
testcase_48 AC 17 ms
10,528 KB
testcase_49 AC 14 ms
6,640 KB
testcase_50 AC 29 ms
10,596 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 31 ms
10,304 KB
testcase_53 AC 12 ms
6,804 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 23 ms
9,000 KB
testcase_56 AC 4 ms
4,380 KB
testcase_57 AC 17 ms
6,720 KB
testcase_58 AC 12 ms
6,716 KB
testcase_59 AC 3 ms
4,376 KB
testcase_60 AC 4 ms
4,376 KB
testcase_61 AC 6 ms
4,376 KB
testcase_62 AC 14 ms
5,868 KB
testcase_63 AC 8 ms
4,376 KB
testcase_64 AC 120 ms
34,948 KB
testcase_65 AC 3 ms
4,380 KB
testcase_66 AC 56 ms
46,828 KB
権限があれば一括ダウンロードができます

ソースコード

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 ----------

fn run() {
    input! {
        n: usize,
        s: usize1,
        t: usize1,
        k: usize,
        x: [i64; n],
        m: usize,
        e: [(usize1, usize1, i64); m],
    }
    let mut g = vec![vec![]; n];
    for (a, b, y) in e {
        g[a].push((b, y));
    }
    let inf = std::i64::MAX / 2;
    let mut dp = vec![vec![(inf, k + 1, n); n]; k + 1];
    dp[1][s].0 = x[s];
    let mut h = std::collections::BinaryHeap::new();
    h.push((-x[s], 1, s));
    while let Some((d, a, v)) = h.pop() {
        let d = -d;
        if d > dp[a][v].0 {
            continue;
        }
        for &(u, w) in g[v].iter() {
            let d = d + w + x[u];
            let b = k.min(a + 1);
            if dp[b][u].0.chmin(d) {
                dp[b][u] = (d, a, v);
                h.push((-d, b, u));
            }
        }
    }
    if dp[k][t].0 == inf {
        println!("Impossible");
        return;
    }
    println!("Possible");
    println!("{}", dp[k][t].0);
    let mut ans = vec![];
    let mut pos = (k, t);
    while pos != (1, s) {
        let (_, a, v) = dp[pos.0][pos.1];
        ans.push(pos.1);
        pos = (a, v);
    }
    ans.push(pos.1);
    ans.reverse();
    println!("{}", ans.len());
    let s = ans.into_iter().map(|s| (s + 1).to_string()).collect::<Vec<_>>().join(" ");
    println!("{}", s);
}

fn main() {
    run();
}
0