結果

問題 No.417 チューリップバブル
ユーザー Kohei AsanoKohei Asano
提出日時 2021-02-04 20:16:16
言語 Rust
(1.77.0)
結果
AC  
実行時間 758 ms / 2,000 ms
コード長 2,370 bytes
コンパイル時間 3,581 ms
コンパイル使用メモリ 152,352 KB
実行使用メモリ 5,108 KB
最終ジャッジ日時 2023-09-13 16:51:35
合計ジャッジ時間 13,346 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 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 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 8 ms
4,376 KB
testcase_09 AC 18 ms
4,376 KB
testcase_10 AC 24 ms
4,376 KB
testcase_11 AC 110 ms
4,376 KB
testcase_12 AC 109 ms
4,376 KB
testcase_13 AC 37 ms
4,376 KB
testcase_14 AC 176 ms
4,380 KB
testcase_15 AC 12 ms
4,376 KB
testcase_16 AC 12 ms
4,376 KB
testcase_17 AC 92 ms
4,376 KB
testcase_18 AC 92 ms
4,380 KB
testcase_19 AC 93 ms
4,376 KB
testcase_20 AC 369 ms
4,376 KB
testcase_21 AC 365 ms
4,380 KB
testcase_22 AC 365 ms
4,376 KB
testcase_23 AC 364 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 367 ms
4,376 KB
testcase_26 AC 32 ms
4,376 KB
testcase_27 AC 255 ms
4,380 KB
testcase_28 AC 365 ms
4,376 KB
testcase_29 AC 361 ms
4,376 KB
testcase_30 AC 363 ms
4,380 KB
testcase_31 AC 362 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 10 ms
4,376 KB
testcase_34 AC 37 ms
4,380 KB
testcase_35 AC 745 ms
5,068 KB
testcase_36 AC 746 ms
5,108 KB
testcase_37 AC 752 ms
5,064 KB
testcase_38 AC 752 ms
5,064 KB
testcase_39 AC 758 ms
5,040 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: function `solve` is never used
 --> Main.rs:1:4
  |
1 | fn solve() {
  |    ^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

ソースコード

diff #

fn solve() {
    let (a, b, c): (usize, usize, usize) = (read(), read(), read());
    println!("{:?}", a + b + c);
    let s: String = read();
    println!("{:?}", s);
}

fn dfs(
    u: usize,
    p: usize,
    time_to_come: usize,
    adjl: &Vec<Vec<(usize, usize)>>,
    dp: &mut Vec<Vec<usize>>,
    m: usize,
    zei: &Vec<usize>,
) {
    for &(v, c) in &adjl[u] {
        if v == p {
            continue;
        }
        if (time_to_come + c) * 2 <= m {
            dfs(v, u, time_to_come + c, adjl, dp, m, zei);
            // 部分木の最適解が求まったとする.
            // その子に行く場合
            // b時間uで使う時間の最適値は求まってなさそう.
            for b in (0..m - c * 2 + 1).rev() {
                for t in 0..m - c * 2 - b + 1 {
                    dp[u][b + 2 * c + t] = max(dp[u][b + 2 * c + t], dp[v][t] + dp[u][b]);
                }
            }
        }
    }
}

fn main() {
    let (n, m): (usize, usize) = (read::<usize>(), read::<usize>());
    let zei: Vec<usize> = (0..n).map(|_| read::<usize>()).collect();
    let mut adjl: Vec<Vec<(usize, usize)>> = vec![vec![]; n];
    for _ in 0..n - 1 {
        let (a, b, c): (usize, usize, usize) = (read::<usize>(), read::<usize>(), read::<usize>());
        adjl[a].push((b, c));
        adjl[b].push((a, c));
    }
    // dp[i][t] ... iでt時間使って集められる税の最大値.
    let mut dp = vec![vec![0; m + 1]; n];
    for i in 0..n {
        for j in 0..m + 1 {
            dp[i][j] = zei[i];
        }
    }
    dfs(0, 0, 0, &adjl, &mut dp, m, &zei);
    let mut res = 0;
    for i in 0..m + 1 {
        res = max(res, dp[0][i]);
    }
    println!("{}", res);
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========
0