結果

問題 No.324 落ちてた閉路グラフ
ユーザー koba-e964koba-e964
提出日時 2016-03-22 22:20:47
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 2,375 bytes
コンパイル時間 1,145 ms
コンパイル使用メモリ 182,040 KB
実行使用メモリ 142,848 KB
最終ジャッジ日時 2024-04-08 22:17:20
合計ジャッジ時間 4,086 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    return ret;
}
#[allow(dead_code)]
fn getword() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.is_err() ||u8b[0] <= ' ' as u8 {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = std::string::String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}
#[allow(dead_code)]
fn parse<T : std::str::FromStr>(s : &str) -> T {
     return s.parse::<T>().ok().unwrap();
}

const MINF: i32 = -300 * 3000 - 10;

fn main() {
    let first_ln = getline();
    let first = first_ln.trim().split(" ").collect::<Vec<_>>();
    let n = parse(first[0]);
    let m: usize = parse(first[1]);
    let second_ln = getline();
    let w: Vec<i32> = second_ln.trim().split(" ").map(|x| parse(x)).collect::<Vec<_>>();
    let mut dp: Vec<Vec<[[i32; 2]; 2]>> = vec![vec![[[MINF; 2]; 2]; n + 1]; n + 1];
assert!(n <= 100);
    dp[0][0][0][0] = 0;
    dp[1][0][0][0] = 0;
    dp[1][1][1][1] = 0;
    for i in 2 .. n {
        dp[i][0][0][0] = 0;
        for j in 1 .. (n + 1) {
            for s in 0 .. 2 {
                for t in 0 .. 2 {
                    dp[i][j][0][t] = max(dp[i][j][0][t], dp[i - 1][j][s][t]);
                    if dp[i - 1][j - 1][s][t] > MINF {
                        dp[i][j][1][t] = max(dp[i][j][1][t], dp[i - 1][j - 1][s][t] + (s as i32) * w[i - 2]);
                    }
                }
            }
        }
    }
    dp[n][0][0][0] = 0;
    for j in 1 .. (n + 1) {
        for s in 0 .. 2 {
            for t in 0 .. 2 {
                dp[n][j][0][t] = max(dp[n][j][0][t], dp[n - 1][j][s][t]);
                if dp[n - 1][j - 1][s][t] > MINF {
                    dp[n][j][1][t] = max(dp[n][j][1][t], dp[n - 1][j - 1][s][t] + (s as i32) * w[n - 2] + (t as i32) * w[n - 1]);
                }
            }
        }
    }
    let mut ma = MINF;
    for s in 0 .. 2 {
        for t in 0 .. 2 {
            ma = max(ma, dp[n][m][s][t]);
        }
    }
    println!("{}", ma);
}
0