結果

問題 No.2495 Three Sets
ユーザー akakimidoriakakimidori
提出日時 2023-10-06 23:00:07
言語 Rust
(1.77.0)
結果
AC  
実行時間 249 ms / 3,000 ms
コード長 3,182 bytes
コンパイル時間 1,182 ms
コンパイル使用メモリ 155,556 KB
実行使用メモリ 6,552 KB
最終ジャッジ日時 2023-10-06 23:00:16
合計ジャッジ時間 6,571 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
4,376 KB
testcase_01 AC 142 ms
4,380 KB
testcase_02 AC 229 ms
4,376 KB
testcase_03 AC 144 ms
4,380 KB
testcase_04 AC 146 ms
4,380 KB
testcase_05 AC 148 ms
4,380 KB
testcase_06 AC 213 ms
4,380 KB
testcase_07 AC 223 ms
4,376 KB
testcase_08 AC 227 ms
4,380 KB
testcase_09 AC 140 ms
4,380 KB
testcase_10 AC 151 ms
4,376 KB
testcase_11 AC 231 ms
4,376 KB
testcase_12 AC 232 ms
4,376 KB
testcase_13 AC 237 ms
4,376 KB
testcase_14 AC 246 ms
5,756 KB
testcase_15 AC 247 ms
4,376 KB
testcase_16 AC 249 ms
6,552 KB
testcase_17 AC 248 ms
6,504 KB
testcase_18 AC 54 ms
4,376 KB
testcase_19 AC 68 ms
6,540 KB
testcase_20 AC 246 ms
6,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    input! {
        x: usize,
        y: usize,
        z: usize,
        a: [i64; x],
        b: [i64; y],
        c: [i64; z],
    }
    let m = 3000;
    let mut memo = vec![vec![(0, 0); 2 * m + 1]; 3];
    for (memo, a) in memo.iter_mut().zip(vec![a, b, c]) {
        for a in a {
            let po = &mut memo[(a + m as i64) as usize];
            po.0 += 1;
            po.1 += a;
        }
        for i in (0..(2 * m)).rev() {
            memo[i].0 += memo[i + 1].0;
            memo[i].1 += memo[i + 1].1;
        }
    }
    let mut ans = 0i64;
    for a in memo[0].iter() {
        for b in memo[1].iter() {
            if a.0 == 0 {
                let val = a.1 * b.0;
                ans.chmax(val);
                ans.chmax(val + b.1 * z as i64);
                continue;
            }
            let key = if b.1 >= 0 {
                -(b.1 / a.0)
            } else {
                (-b.1 + a.0 - 1) / a.0
            };
            let c = if key < -(m as i64) {
                memo[2][0]
            } else {
                memo[2][(key + m as i64).min(2 * m as i64) as usize]
            };
            ans.chmax(a.1 * b.0 + b.1 * c.0 + c.1 * a.0);
        }
    }
    println!("{}", ans);
}

// ---------- 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_export]
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_export]
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_export]
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 ----------
0