結果

問題 No.1460 Max of Min
ユーザー akakimidoriakakimidori
提出日時 2021-12-09 04:21:13
言語 Rust
(1.77.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 2,680 bytes
コンパイル時間 1,256 ms
コンパイル使用メモリ 154,480 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-23 15:16:52
合計ジャッジ時間 6,706 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 112 ms
4,376 KB
testcase_04 AC 111 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 113 ms
4,380 KB
testcase_07 AC 112 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 112 ms
4,376 KB
testcase_11 AC 112 ms
4,376 KB
testcase_12 AC 11 ms
4,376 KB
testcase_13 AC 42 ms
4,376 KB
testcase_14 AC 15 ms
4,376 KB
testcase_15 AC 8 ms
4,380 KB
testcase_16 AC 38 ms
4,380 KB
testcase_17 AC 17 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 20 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 22 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 25 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 44 ms
4,380 KB
testcase_27 AC 8 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 23 ms
4,376 KB
testcase_30 AC 33 ms
4,376 KB
testcase_31 AC 19 ms
4,380 KB
testcase_32 AC 7 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 4 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 4 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 4 ms
4,380 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 10 ms
4,380 KB
testcase_44 AC 15 ms
4,376 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 7 ms
4,376 KB
testcase_47 AC 8 ms
4,376 KB
testcase_48 AC 18 ms
4,380 KB
testcase_49 AC 14 ms
4,380 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 11 ms
4,380 KB
testcase_52 AC 3 ms
4,380 KB
testcase_53 AC 3 ms
4,380 KB
testcase_54 AC 4 ms
4,376 KB
testcase_55 AC 22 ms
4,376 KB
testcase_56 AC 3 ms
4,376 KB
testcase_57 AC 14 ms
4,376 KB
testcase_58 AC 105 ms
4,376 KB
testcase_59 AC 13 ms
4,376 KB
testcase_60 AC 15 ms
4,376 KB
testcase_61 AC 5 ms
4,380 KB
testcase_62 AC 5 ms
4,380 KB
testcase_63 AC 1 ms
4,380 KB
testcase_64 AC 2 ms
4,376 KB
testcase_65 AC 23 ms
4,380 KB
testcase_66 AC 4 ms
4,376 KB
testcase_67 AC 1 ms
4,376 KB
testcase_68 AC 16 ms
4,376 KB
testcase_69 AC 11 ms
4,376 KB
testcase_70 AC 8 ms
4,380 KB
testcase_71 AC 21 ms
4,380 KB
testcase_72 AC 4 ms
4,380 KB
testcase_73 AC 4 ms
4,376 KB
testcase_74 AC 3 ms
4,380 KB
testcase_75 AC 3 ms
4,376 KB
testcase_76 AC 3 ms
4,376 KB
testcase_77 AC 3 ms
4,380 KB
testcase_78 AC 1 ms
4,376 KB
testcase_79 AC 3 ms
4,376 KB
testcase_80 AC 3 ms
4,376 KB
testcase_81 AC 1 ms
4,376 KB
testcase_82 AC 3 ms
4,380 KB
testcase_83 AC 2 ms
4,376 KB
testcase_84 AC 107 ms
4,376 KB
testcase_85 AC 106 ms
4,376 KB
testcase_86 AC 106 ms
4,380 KB
testcase_87 AC 109 ms
4,380 KB
testcase_88 AC 105 ms
4,380 KB
testcase_89 AC 110 ms
4,380 KB
testcase_90 AC 110 ms
4,380 KB
testcase_91 AC 107 ms
4,376 KB
testcase_92 AC 103 ms
4,380 KB
testcase_93 AC 102 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

pub trait SemiRing: Clone {
    fn zero() -> Self;
    fn one() -> Self;
    fn add(&self, rhs: &Self) -> Self;
    fn mul(&self, rhs: &Self) -> Self;
}

pub struct Kitamasa<T> {
    c: Vec<T>,
    tmp: std::cell::RefCell<Vec<T>>,
}

impl<T: SemiRing> Kitamasa<T> {
    pub fn new(c: Vec<T>) -> Self {
        assert!(!c.is_empty());
        Self {
            c: c,
            tmp: std::cell::RefCell::new(vec![]),
        }
    }
    pub fn normalize(&self, d: &mut Vec<T>) {
        let n = self.c.len();
        for i in (n..d.len()).rev() {
            let v = d.pop().unwrap();
            for (d, c) in d[(i - n)..].iter_mut().zip(&self.c) {
                *d = d.add(&v.mul(c));
            }
        }
    }
    pub fn next(&self, d: &mut Vec<T>) {
        d.insert(0, T::zero());
        self.normalize(d);
    }
    pub fn twice(&self, d: &mut Vec<T>) {
        assert!(!d.is_empty());
        let mut tmp = self.tmp.borrow_mut();
        tmp.clear();
        tmp.resize(d.len() * 2 - 1, T::zero());
        for (i, a) in d.iter().enumerate() {
            for (tmp, b) in tmp[i..].iter_mut().zip(d.iter()) {
                *tmp = tmp.add(&a.mul(b));
            }
        }
        std::mem::swap(&mut *tmp, d);
        drop(tmp);
        self.normalize(d);
    }
    pub fn kth_coefficient(&self, k: usize) -> Vec<T> {
        let mut t = vec![T::one()];
        if k > 0 {
            let p = (k + 1).next_power_of_two().trailing_zeros() - 1;
            for i in (0..=p).rev() {
                self.twice(&mut t);
                if k >> i & 1 == 1 {
                    self.next(&mut t);
                }
            }
        }
        t.resize(self.c.len(), T::zero());
        t
    }
}

fn read() -> (usize, Vec<i64>, Vec<i64>) {
    let mut s = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let mut next = || it.next().unwrap().parse::<i64>().unwrap();
    let k = next() as usize;
    let n = next() as usize;
    let a = (0..k).map(|_| next()).collect::<Vec<_>>();
    let b = (0..k).map(|_| next()).collect::<Vec<_>>();
    (n, a, b)
}

impl SemiRing for i64 {
    fn zero() -> Self {
        std::i64::MIN
    }
    fn one() -> Self {
        std::i64::MAX
    }
    fn add(&self, rhs: &Self) -> Self {
        std::cmp::max(*self, *rhs)
    }
    fn mul(&self, rhs: &Self) -> Self {
        std::cmp::min(*self, *rhs)
    }
}

fn main() {
    let (n, a, b) = read();
    let solver = Kitamasa::new(b);
    let d = solver.kth_coefficient(n);
    let ans = a.into_iter().zip(d).fold(std::i64::MIN, |s, p| s.max(p.0.min(p.1)));
    println!("{}", ans);
}
0