結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー phsplsphspls
提出日時 2022-10-14 23:48:28
言語 Rust
(1.77.0)
結果
AC  
実行時間 635 ms / 2,000 ms
コード長 1,784 bytes
コンパイル時間 7,355 ms
コンパイル使用メモリ 158,020 KB
実行使用メモリ 28,324 KB
最終ジャッジ日時 2023-09-09 00:17:01
合計ジャッジ時間 12,592 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,332 KB
testcase_01 AC 1 ms
4,360 KB
testcase_02 AC 1 ms
4,356 KB
testcase_03 AC 1 ms
4,360 KB
testcase_04 AC 74 ms
18,004 KB
testcase_05 AC 55 ms
13,588 KB
testcase_06 AC 12 ms
5,520 KB
testcase_07 AC 14 ms
6,272 KB
testcase_08 AC 75 ms
23,564 KB
testcase_09 AC 60 ms
11,408 KB
testcase_10 AC 196 ms
5,800 KB
testcase_11 AC 58 ms
15,824 KB
testcase_12 AC 39 ms
8,972 KB
testcase_13 AC 48 ms
18,468 KB
testcase_14 AC 41 ms
6,564 KB
testcase_15 AC 48 ms
17,856 KB
testcase_16 AC 44 ms
7,096 KB
testcase_17 AC 30 ms
16,060 KB
testcase_18 AC 46 ms
18,732 KB
testcase_19 AC 88 ms
22,452 KB
testcase_20 AC 18 ms
6,864 KB
testcase_21 AC 36 ms
10,072 KB
testcase_22 AC 43 ms
6,672 KB
testcase_23 AC 69 ms
19,952 KB
testcase_24 AC 96 ms
25,960 KB
testcase_25 AC 102 ms
26,032 KB
testcase_26 AC 101 ms
26,020 KB
testcase_27 AC 102 ms
26,032 KB
testcase_28 AC 94 ms
26,008 KB
testcase_29 AC 101 ms
26,012 KB
testcase_30 AC 99 ms
26,012 KB
testcase_31 AC 104 ms
26,040 KB
testcase_32 AC 102 ms
26,068 KB
testcase_33 AC 101 ms
26,100 KB
testcase_34 AC 112 ms
8,128 KB
testcase_35 AC 206 ms
7,428 KB
testcase_36 AC 209 ms
7,384 KB
testcase_37 AC 332 ms
8,196 KB
testcase_38 AC 149 ms
7,740 KB
testcase_39 AC 635 ms
6,700 KB
testcase_40 AC 450 ms
7,880 KB
testcase_41 AC 526 ms
6,688 KB
testcase_42 AC 504 ms
6,852 KB
testcase_43 AC 476 ms
7,880 KB
testcase_44 AC 66 ms
28,324 KB
testcase_45 AC 65 ms
28,324 KB
testcase_46 AC 62 ms
28,256 KB
testcase_47 AC 63 ms
28,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::VecDeque;


fn main() {
    let mut nm = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<usize> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nm[0];
    let m = nm[1];
    let mut h = String::new();
    std::io::stdin().read_line(&mut h).ok();
    let h: Vec<isize> = h.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut paths = vec![vec![vec![]; n]; 2];
    for _ in 0..m {
        let mut temp = String::new();
        std::io::stdin().read_line(&mut temp).ok();
        let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let x = temp[0]-1;
        let y = temp[1]-1;
        paths[0][x].push(y);
        paths[1][y].push(x);
    }

    for i in 0..2 { for j in 0..n { paths[i][j].sort(); } }
    let mut dp = vec![vec![vec![-1isize; 2]; n]; 2];
    dp[0][0][0] = 0;
    dp[1][n-1][0] = 0;
    for player in 0..2 {
        let mut deque = VecDeque::new();
        if player == 0 {
            deque.push_back((0usize, 0));
        } else {
            deque.push_back((n-1, 0));
        }
        while let Some((u, up_cnt)) = deque.pop_front() {
            for &v in paths[player][u].iter() {
                if h[u] < h[v] && up_cnt == 1 { continue; }
                let nup_cnt = if h[u] < h[v] { 1 } else { 0 };
                let nup_cost = dp[player][u][up_cnt] + if h[u] < h[v] { h[v] - h[u] } else { 0 };
                if dp[player][v][nup_cnt] >= nup_cost { continue; }
                dp[player][v][nup_cnt] = nup_cost;
                deque.push_back((v, nup_cnt));
            }
        }
    }
    println!("{}", dp[0][n-1].iter().max().unwrap());
    println!("{}", dp[1][0].iter().max().unwrap());
}
0