結果

問題 No.572 妖精の演奏
ユーザー hatoohatoo
提出日時 2017-10-12 00:45:00
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 3,604 bytes
コンパイル時間 13,859 ms
コンパイル使用メモリ 379,260 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 16:23:57
合計ジャッジ時間 12,695 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,248 KB
testcase_01 AC 7 ms
5,376 KB
testcase_02 AC 7 ms
5,376 KB
testcase_03 AC 7 ms
5,376 KB
testcase_04 AC 5 ms
5,376 KB
testcase_05 AC 18 ms
5,376 KB
testcase_06 AC 27 ms
5,376 KB
testcase_07 AC 20 ms
5,376 KB
testcase_08 AC 19 ms
5,376 KB
testcase_09 AC 29 ms
5,376 KB
testcase_10 AC 151 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 152 ms
5,376 KB
testcase_13 AC 158 ms
5,376 KB
testcase_14 AC 84 ms
5,376 KB
testcase_15 AC 97 ms
5,376 KB
testcase_16 AC 88 ms
5,376 KB
testcase_17 AC 90 ms
5,376 KB
testcase_18 AC 13 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }

    #[allow(dead_code)]
    pub fn get3<S: FromStr, T: FromStr, U: FromStr>() -> (S, T, U)
    where
        <S as FromStr>::Err: Debug,
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}


#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn main() {
    let n: usize = util::get();
    let m: usize = util::get();
    let a: Vec<Vec<usize>> = (0..m).map(|_| util::gets()).collect();

    let ans = (0..m)
        .map(|s| {
            let b = 1000;
            let mut dp = vec![vec![0; m]; b + 1];
            for i in 1..b + 1 {
                for k in 0..m {
                    if i == 1 {
                        dp[i][k] = a[s][k];
                    } else {
                        for j in 0..m {
                            dp[i][k] = max(dp[i][k], dp[i - 1][j] + a[j][k]);
                        }
                    }
                }
            }
            let (l, v) = (1..b + 1)
                .map(|i| (i, dp[i][s]))
                .max_by_key(|&(l, v)| v * 1000000 / l)
                .unwrap();

            let len = 1000;
            let mut ans = 0;
            let mut n = n;
            if n > len {
                let c = (n - len) / l;
                ans += c * v;
                n = n - c * l;
            }

            let mut dp = vec![vec![0; m]; n];
            for i in 1..n {
                for k in 0..m {
                    if i == 1 {
                        dp[i][k] = a[s][k];
                    } else {
                        for j in 0..m {
                            dp[i][k] = max(dp[i][k], dp[i - 1][j] + a[j][k]);
                        }
                    }
                }
            }
            ans + (0..m).map(|i| dp[n - 1][i]).max().unwrap()
        })
        .max()
        .unwrap();

    println!("{}", ans);
}
0