結果

問題 No.1676 Coin Trade (Single)
ユーザー phsplsphspls
提出日時 2022-10-20 22:38:05
言語 Rust
(1.77.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,293 bytes
コンパイル時間 5,670 ms
コンパイル使用メモリ 137,540 KB
実行使用メモリ 18,836 KB
最終ジャッジ日時 2023-09-13 02:51:20
合計ジャッジ時間 9,446 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 45 ms
13,824 KB
testcase_04 AC 39 ms
12,500 KB
testcase_05 AC 34 ms
11,180 KB
testcase_06 AC 35 ms
11,404 KB
testcase_07 AC 29 ms
9,608 KB
testcase_08 AC 16 ms
6,548 KB
testcase_09 AC 29 ms
9,296 KB
testcase_10 AC 29 ms
9,820 KB
testcase_11 AC 46 ms
14,328 KB
testcase_12 AC 22 ms
7,752 KB
testcase_13 AC 1 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,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 62 ms
18,828 KB
testcase_34 AC 61 ms
18,772 KB
testcase_35 AC 64 ms
18,760 KB
testcase_36 AC 61 ms
18,760 KB
testcase_37 AC 64 ms
18,836 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `k`
 --> Main.rs:9:9
  |
9 |     let k = nk[1];
  |         ^ help: if this is intentional, prefix it with an underscore: `_k`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `i`
  --> Main.rs:12:9
   |
12 |     for i in 0..n {
   |         ^ help: if this is intentional, prefix it with an underscore: `_i`

warning: 2 warnings emitted

ソースコード

diff #

const INF: isize = 1isize << 60;

fn main() {
    let mut nk = String::new();
    std::io::stdin().read_line(&mut nk).ok();
    let nk: Vec<usize> = nk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nk[0];
    let k = nk[1];
    let mut avals = Vec::with_capacity(n);
    let mut bs = Vec::with_capacity(n);
    for i in 0..n {
        let mut am = String::new();
        std::io::stdin().read_line(&mut am).ok();
        let am: Vec<isize> = am.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let a = am[0];
        let mut b = String::new();
        std::io::stdin().read_line(&mut b).ok();
        let b: Vec<usize> = b.trim().split_whitespace().map(|s| s.parse::<usize>().unwrap()-1).collect();
        avals.push(a);
        bs.push(b);
    }
    let mut paths = vec![vec![]; n];
    for u in 0..n {
        for &v in bs[u].iter() {
            paths[v].push((u, avals[v] - avals[u]));
        }
        if u+1 < n {
            paths[u].push((u+1, 0));
        }
    }
    let mut result = vec![INF; n];
    result[0] = 0;
    for u in 0..n {
        for &(v, cost) in paths[u].iter() {
            if v <= u { continue; }
            result[v] = result[v].min(result[u] + cost);
        }
    }
    println!("{}", -result[n-1]);
}
0