結果

問題 No.1515 Making Many Multiples
ユーザー koba-e964koba-e964
提出日時 2021-11-19 00:17:43
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,713 bytes
コンパイル時間 2,676 ms
コンパイル使用メモリ 152,988 KB
実行使用メモリ 17,552 KB
最終ジャッジ日時 2023-08-27 19:12:19
合計ジャッジ時間 4,156 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 106 ms
17,524 KB
testcase_05 WA -
testcase_06 AC 66 ms
17,536 KB
testcase_07 AC 72 ms
17,528 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 55 ms
9,832 KB
testcase_11 AC 86 ms
12,440 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 17 ms
12,252 KB
testcase_19 AC 5 ms
6,432 KB
testcase_20 WA -
testcase_21 AC 68 ms
17,000 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 WA -
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 86 ms
17,276 KB
testcase_28 AC 49 ms
17,264 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 7 ms
4,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, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    input! {
        n: usize, k: usize, x: usize, y: usize,
        a: [usize; n],
    }
    const INF: i32 = 1 << 28;
    let mut dp = vec![vec![-INF; k]; k];
    dp[x % k][y % k] = 0;
    let mut row = vec![-INF; k];
    let mut col = vec![-INF; k];
    row[x % k] = 0;
    col[y % k] = 0;
    for &a in &a {
        let a = a % k;
        for b in 0..k {
            let mut ma = max(row[b], col[b]);
            let rest = (2 * k - a - b) % k;
            ma = max(ma, max(dp[rest][b], dp[b][rest]) + 1);
            dp[a][b] = ma;
        }
        for b in 0..k {
            row[a] = max(row[a], dp[a][b]);
            col[b] = max(col[b], dp[a][b]);
        }
    }
    let ans = row.iter().max().unwrap();
    println!("{}", ans);
}
0