結果

問題 No.2423 Merge Stones
コンテスト
ユーザー ngtkana
提出日時 2026-08-18 02:06:06
言語 Rust
(1.94.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
WA  
実行時間 -
コード長 884 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,897 ms
コンパイル使用メモリ 190,008 KB
実行使用メモリ 7,340 KB
最終ジャッジ日時 2026-08-18 02:06:28
合計ジャッジ時間 9,306 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11 WA * 61
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

use proconio::input;

fn main() {
    input! {
        n: usize,
        k: u32,
        a: [u64; n],
        c: [u32; n],
    }
    let mut dp = vec![vec![0; n]; n];
    for (i, &c) in c.iter().enumerate() {
        dp[(i + 1) % n][i] = 1 << c;
    }
    for d in 2..=n {
        for l in 0..n {
            let r = l + d;
            for c in l + 1..r {
                let c = c % n;
                let r = r % n;
                let x = dp[c][l];
                let y = dp[r][c];
                let z = x & (y | y << k | y >> k) | y & (x | x << k | x >> k);
                dp[r][l] |= z;
            }
        }
    }
    let mut ans = 0;
    for l in 0..n {
        let mut sum = a[l];
        for r in (l + 1..n).chain(0..l) {
            if dp[r][l] != 0 {
                ans = ans.max(sum);
            }
            sum += a[r];
        }
    }
    println!("{ans}");
}
0