結果

問題 No.1247 ブロック登り
ユーザー ngtkanangtkana
提出日時 2020-07-01 22:53:33
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,570 bytes
コンパイル時間 2,200 ms
コンパイル使用メモリ 160,896 KB
実行使用メモリ 111,616 KB
最終ジャッジ日時 2024-04-17 03:10:41
合計ジャッジ時間 9,495 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 628 ms
111,616 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 9 ms
5,376 KB
testcase_23 AC 7 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 602 ms
111,616 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::stdin;

trait OrdTools: Ord + Clone + Sized {
    fn chmin(&mut self, x: Self) {
        *self = std::cmp::min(self.clone(), x);
    }
    fn chmax(&mut self, x: Self) {
        *self = std::cmp::max(self.clone(), x);
    }
}

impl<T: Ord + Clone + Sized> OrdTools for T {}

fn main() {
    let (n, l) = {
        let mut s = String::new();
        stdin().read_line(&mut s).unwrap();
        let s = s.trim_end().to_owned();
        let mut s = s.split_whitespace();
        let n: usize = s.next().unwrap().parse().unwrap();
        let l: usize = s.next().unwrap().parse().unwrap();
        assert!(s.next().is_none());
        (n, l)
    };
    let a = {
        let mut s = String::new();
        stdin().read_line(&mut s).unwrap();
        let s = s.trim_end().to_owned();
        let mut s = s.split_whitespace();
        let mut a = vec![0; n];
        a.iter_mut()
            .for_each(|x| *x = s.next().unwrap().parse().unwrap());
        assert!(s.next().is_none());
        a
    };
    let mut ans = vec![std::i32::MIN; n];
    let mut dp = vec![vec![vec![std::i32::MIN; n]; n]; l + 1];

    (0..n).for_each(|j| dp[l][j][j] = l as i32 * a[j]);
    for i in (0..=l).rev() {
        if i + 3 <= l {
            let prv = dp[i + 2].clone();
            for j in 0..n {
                for k in 0..n {
                    dp[i][j][k].chmax(prv[j][k]);
                }
            }
        }
        for j in 0..n {
            let crr = dp[i][j].clone();
            let mut update = |ni: usize, nj: usize, nk: usize, k| {
                dp[ni][nj][nk].chmax(crr[k] + ni as i32 * a[nj]);
            };
            for k in (0..=j).filter(|&k| crr[k] != std::i32::MIN) {
                let d = j - k;
                if d + 1 <= i && 0 < k {
                    update(i - d - 1, k - 1, j, k);
                }
                if 0 < i && j < n - 1 {
                    update(i - 1, j + 1, k, k);
                }
            }
            for k in (j..n).filter(|&k| crr[k] != std::i32::MIN) {
                let d = k - j;
                if 0 < i && 0 < j {
                    update(i - 1, j - 1, k, k);
                }
                if d + 1 <= i && k < n - 1 {
                    update(i - d - 1, k + 1, j, k);
                }
            }
            if j + i < n {
                (j + 1..n).for_each(|k| ans[j + i].chmax(crr[k]));
            }
            if i <= j {
                (0..=j - i).for_each(|k| ans[j - i].chmax(crr[k]));
            }
        }
    }

    ans.iter().for_each(|x| println!("{}", x));
}
0