結果

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

ソースコード

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![0u64; n]; n];
    for (i, &c) in c.iter().enumerate() {
        dp[(i + 1) % n][i] = 1 << c;
    }
    for d in 2..=n {
        for e in 1..d {
            for l in 0..n {
                let c = (l + e) % n;
                let r = (l + d) % n;
                let x = dp[c][l];
                let y = dp[r][c];
                dp[r][l] |= (x | y) & widen(x, k) & widen(y, k);
            }
        }
    }
    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];
        }
        if dp[l][l] != 0 {
            ans = ans.max(sum);
        }
    }
    println!("{ans}");
}

const fn widen(mut x: u64, k: u32) -> u64 {
    match k {
        0 => x,
        1 => x | x << 1 | x >> 1,
        2 => {
            x <<= 1;
            x <<= 2;
            x <<= 2;
            x >> 2
        }
        3 => {
            x <<= 1;
            x <<= 2;
            x <<= 4;
            x >> 3
        }
        4 => {
            x <<= 1;
            x <<= 2;
            x <<= 4;
            x <<= 2;
            x >> 4
        }
        5 => {
            x <<= 1;
            x <<= 2;
            x <<= 4;
            x <<= 4;
            x >> 5
        }
        _ => unreachable!(),
    }
}
0