結果

問題 No.1247 ブロック登り
ユーザー ngtkanangtkana
提出日時 2020-07-01 22:41:47
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,907 bytes
コンパイル時間 1,473 ms
コンパイル使用メモリ 177,604 KB
実行使用メモリ 111,744 KB
最終ジャッジ日時 2024-04-17 03:10:24
合計ジャッジ時間 8,732 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 0 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 559 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 3 ms
5,376 KB
testcase_22 AC 8 ms
5,376 KB
testcase_23 AC 6 ms
5,376 KB
testcase_24 AC 0 ms
5,376 KB
testcase_25 AC 556 ms
111,616 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::input;

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() {
    input!(n: usize, l: usize, a: [i32; n]);
    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