結果

問題 No.1515 Making Many Multiples
ユーザー akakimidoriakakimidori
提出日時 2021-05-21 22:15:35
言語 Rust
(1.77.0)
結果
AC  
実行時間 486 ms / 2,000 ms
コード長 3,132 bytes
コンパイル時間 1,315 ms
コンパイル使用メモリ 172,184 KB
実行使用メモリ 18,176 KB
最終ジャッジ日時 2024-04-18 15:45:09
合計ジャッジ時間 8,530 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 483 ms
18,048 KB
testcase_03 AC 486 ms
18,176 KB
testcase_04 AC 472 ms
17,792 KB
testcase_05 AC 477 ms
18,176 KB
testcase_06 AC 336 ms
18,176 KB
testcase_07 AC 362 ms
18,176 KB
testcase_08 AC 206 ms
6,944 KB
testcase_09 AC 255 ms
9,728 KB
testcase_10 AC 258 ms
10,112 KB
testcase_11 AC 345 ms
13,056 KB
testcase_12 AC 199 ms
8,576 KB
testcase_13 AC 13 ms
6,944 KB
testcase_14 AC 371 ms
14,336 KB
testcase_15 AC 14 ms
6,944 KB
testcase_16 AC 442 ms
16,896 KB
testcase_17 AC 71 ms
9,984 KB
testcase_18 AC 47 ms
12,544 KB
testcase_19 AC 9 ms
6,940 KB
testcase_20 AC 73 ms
6,940 KB
testcase_21 AC 265 ms
17,408 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 296 ms
17,536 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 1 ms
6,944 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 411 ms
17,536 KB
testcase_28 AC 213 ms
17,792 KB
testcase_29 AC 12 ms
6,940 KB
testcase_30 AC 39 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// ---------- begin chmin, chmax ----------
pub trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

fn run() {
    input! {
        n: usize,
        k: usize,
        x: usize,
        y: usize,
        a: [usize; n],
    }
    let (x, y) = (x % k, y % k);
    let a = a.iter().map(|a| *a % k).collect::<Vec<_>>();
    let inf = 20000i32;
    let mut dp = vec![vec![-inf; k]; k];
    let mut max = vec![-inf; k];
    dp[(x + y) % k][x] = 0;
    dp[(x + y) % k][y] = 0;
    max[x] = 0;
    max[y] = 0;
    for a in a {
        let p = (k - a) % k;
        let mut update = vec![];
        for (j, dp) in dp[p].iter_mut().enumerate() {
            *dp += 1;
            let x = (3 * k - a - j) % k;
            update.push(((a + j) % k, a, *dp));
            update.push(((a + j) % k, j, *dp));
            update.push(((a + x) % k, a, *dp));
            update.push(((a + x) % k, x, *dp));
            update.push(((x + j) % k, x, *dp));
            update.push(((x + j) % k, j, *dp));
        }
        for j in 0..k {
            update.push(((a + j) % k, j, max[j]));
            update.push(((a + j) % k, a, max[j]));
        }
        for (a, b, c) in update {
            dp[a][b].chmax(c);
            max[b].chmax(c);
        }
    }
    println!("{}", dp.into_iter().flatten().max().unwrap());
}

fn main() {
    run();
}
0