結果

問題 No.2423 Merge Stones
ユーザー koba-e964koba-e964
提出日時 2023-08-13 23:20:54
言語 Rust
(1.77.0)
結果
AC  
実行時間 2,210 ms / 4,000 ms
コード長 2,151 bytes
コンパイル時間 12,509 ms
コンパイル使用メモリ 402,328 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-01 12:58:10
合計ジャッジ時間 93,334 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 0 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2,112 ms
5,376 KB
testcase_12 AC 1,035 ms
5,376 KB
testcase_13 AC 1,038 ms
5,376 KB
testcase_14 AC 1,038 ms
5,376 KB
testcase_15 AC 1,038 ms
5,376 KB
testcase_16 AC 1,038 ms
5,376 KB
testcase_17 AC 1,035 ms
5,376 KB
testcase_18 AC 1,036 ms
5,376 KB
testcase_19 AC 1,038 ms
5,376 KB
testcase_20 AC 1,036 ms
5,376 KB
testcase_21 AC 1,040 ms
5,376 KB
testcase_22 AC 1,037 ms
5,376 KB
testcase_23 AC 1,038 ms
5,376 KB
testcase_24 AC 1,037 ms
5,376 KB
testcase_25 AC 1,035 ms
5,376 KB
testcase_26 AC 1,046 ms
5,376 KB
testcase_27 AC 1,034 ms
5,376 KB
testcase_28 AC 1,043 ms
5,376 KB
testcase_29 AC 1,036 ms
5,376 KB
testcase_30 AC 1,038 ms
5,376 KB
testcase_31 AC 1,036 ms
5,376 KB
testcase_32 AC 1,038 ms
5,376 KB
testcase_33 AC 1,037 ms
5,376 KB
testcase_34 AC 1,038 ms
5,376 KB
testcase_35 AC 1,037 ms
5,376 KB
testcase_36 AC 1,039 ms
5,376 KB
testcase_37 AC 1,036 ms
5,376 KB
testcase_38 AC 1,036 ms
5,376 KB
testcase_39 AC 1,036 ms
5,376 KB
testcase_40 AC 1,036 ms
5,376 KB
testcase_41 AC 1,035 ms
5,376 KB
testcase_42 AC 1,038 ms
5,376 KB
testcase_43 AC 1,038 ms
5,376 KB
testcase_44 AC 1,036 ms
5,376 KB
testcase_45 AC 1,037 ms
5,376 KB
testcase_46 AC 1,036 ms
5,376 KB
testcase_47 AC 1,035 ms
5,376 KB
testcase_48 AC 1,039 ms
5,376 KB
testcase_49 AC 1,035 ms
5,376 KB
testcase_50 AC 1,039 ms
5,376 KB
testcase_51 AC 1,392 ms
5,376 KB
testcase_52 AC 1,430 ms
5,376 KB
testcase_53 AC 1,399 ms
5,376 KB
testcase_54 AC 1,401 ms
5,376 KB
testcase_55 AC 1,428 ms
5,376 KB
testcase_56 AC 1,038 ms
5,376 KB
testcase_57 AC 1,038 ms
5,376 KB
testcase_58 AC 1,048 ms
5,376 KB
testcase_59 AC 1,042 ms
5,376 KB
testcase_60 AC 1,040 ms
5,376 KB
testcase_61 AC 2,036 ms
5,376 KB
testcase_62 AC 2,169 ms
5,376 KB
testcase_63 AC 1,946 ms
5,376 KB
testcase_64 AC 2,094 ms
5,376 KB
testcase_65 AC 2,079 ms
5,376 KB
testcase_66 AC 2,095 ms
5,376 KB
testcase_67 AC 2,210 ms
5,376 KB
testcase_68 AC 2,044 ms
5,376 KB
testcase_69 AC 2,138 ms
5,376 KB
testcase_70 AC 1,919 ms
5,376 KB
testcase_71 AC 1,715 ms
5,376 KB
testcase_72 AC 1,703 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    input! {
        n: usize, k: usize,
        a: [i64; n],
        c: [usize1; n],
    }
    let mut acc = vec![0; 2 * n + 1];
    for i in 0..2 * n {
        acc[i + 1] = acc[i] + a[i % n];
    }
    const C: usize = 50;
    let mut ans = 0;
    let mut dp = vec![vec![0u64; 2 * n + 1]; 2 * n];
    for i in 0..2 * n {
        let u = i % n;
        dp[i][i + 1] |= 1 << c[u];
        ans = max(ans, a[u]);
    }
    for s in 2..n + 1 {
        for i in 0..2 * n - s + 1 {
            let j = i + s;
            let mut me = 0u64;
            for l in i + 1..j {
                for b in 0..C {
                    if (dp[i][l] & 1 << b) != 0 {
                        let bits = (1 << (b + k + 1)) - (1 << b);
                        let bits = bits | bits >> k;
                        if (dp[l][j] & bits) != 0 {
                            me |= 1 << b | (dp[l][j] & bits);
                        }
                    }
                }
            }
            dp[i][j] = me;
            if me != 0 {
                ans = max(ans, acc[j] - acc[i]);
            }
        }
    }
    println!("{}", ans);
}
0