結果
問題 | No.1460 Max of Min |
ユーザー | akakimidori |
提出日時 | 2021-12-09 04:21:13 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 178 ms / 2,000 ms |
コード長 | 2,680 bytes |
コンパイル時間 | 13,820 ms |
コンパイル使用メモリ | 396,796 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-16 15:01:31 |
合計ジャッジ時間 | 20,452 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 173 ms
5,376 KB |
testcase_04 | AC | 173 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 177 ms
5,376 KB |
testcase_07 | AC | 178 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 175 ms
5,376 KB |
testcase_11 | AC | 174 ms
5,376 KB |
testcase_12 | AC | 16 ms
5,376 KB |
testcase_13 | AC | 66 ms
5,376 KB |
testcase_14 | AC | 24 ms
5,376 KB |
testcase_15 | AC | 12 ms
5,376 KB |
testcase_16 | AC | 57 ms
5,376 KB |
testcase_17 | AC | 25 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 30 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 5 ms
5,376 KB |
testcase_22 | AC | 34 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 38 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 69 ms
5,376 KB |
testcase_27 | AC | 12 ms
5,376 KB |
testcase_28 | AC | 4 ms
5,376 KB |
testcase_29 | AC | 37 ms
5,376 KB |
testcase_30 | AC | 50 ms
5,376 KB |
testcase_31 | AC | 30 ms
5,376 KB |
testcase_32 | AC | 10 ms
5,376 KB |
testcase_33 | AC | 2 ms
5,376 KB |
testcase_34 | AC | 6 ms
5,376 KB |
testcase_35 | AC | 3 ms
5,376 KB |
testcase_36 | AC | 1 ms
5,376 KB |
testcase_37 | AC | 5 ms
5,376 KB |
testcase_38 | AC | 2 ms
5,376 KB |
testcase_39 | AC | 5 ms
5,376 KB |
testcase_40 | AC | 4 ms
5,376 KB |
testcase_41 | AC | 3 ms
5,376 KB |
testcase_42 | AC | 2 ms
5,376 KB |
testcase_43 | AC | 15 ms
5,376 KB |
testcase_44 | AC | 24 ms
5,376 KB |
testcase_45 | AC | 1 ms
5,376 KB |
testcase_46 | AC | 10 ms
5,376 KB |
testcase_47 | AC | 12 ms
5,376 KB |
testcase_48 | AC | 28 ms
5,376 KB |
testcase_49 | AC | 21 ms
5,376 KB |
testcase_50 | AC | 2 ms
5,376 KB |
testcase_51 | AC | 16 ms
5,376 KB |
testcase_52 | AC | 4 ms
5,376 KB |
testcase_53 | AC | 5 ms
5,376 KB |
testcase_54 | AC | 6 ms
5,376 KB |
testcase_55 | AC | 32 ms
5,376 KB |
testcase_56 | AC | 4 ms
5,376 KB |
testcase_57 | AC | 21 ms
5,376 KB |
testcase_58 | AC | 162 ms
5,376 KB |
testcase_59 | AC | 19 ms
5,376 KB |
testcase_60 | AC | 23 ms
5,376 KB |
testcase_61 | AC | 6 ms
5,376 KB |
testcase_62 | AC | 6 ms
5,376 KB |
testcase_63 | AC | 1 ms
5,376 KB |
testcase_64 | AC | 1 ms
5,376 KB |
testcase_65 | AC | 34 ms
5,376 KB |
testcase_66 | AC | 6 ms
5,376 KB |
testcase_67 | AC | 2 ms
5,376 KB |
testcase_68 | AC | 23 ms
5,376 KB |
testcase_69 | AC | 16 ms
5,376 KB |
testcase_70 | AC | 11 ms
5,376 KB |
testcase_71 | AC | 30 ms
5,376 KB |
testcase_72 | AC | 6 ms
5,376 KB |
testcase_73 | AC | 5 ms
5,376 KB |
testcase_74 | AC | 6 ms
5,376 KB |
testcase_75 | AC | 4 ms
5,376 KB |
testcase_76 | AC | 4 ms
5,376 KB |
testcase_77 | AC | 4 ms
5,376 KB |
testcase_78 | AC | 2 ms
5,376 KB |
testcase_79 | AC | 5 ms
5,376 KB |
testcase_80 | AC | 3 ms
5,376 KB |
testcase_81 | AC | 1 ms
5,376 KB |
testcase_82 | AC | 3 ms
5,376 KB |
testcase_83 | AC | 2 ms
5,376 KB |
testcase_84 | AC | 165 ms
5,376 KB |
testcase_85 | AC | 163 ms
5,376 KB |
testcase_86 | AC | 153 ms
5,376 KB |
testcase_87 | AC | 158 ms
5,376 KB |
testcase_88 | AC | 159 ms
5,376 KB |
testcase_89 | AC | 175 ms
5,376 KB |
testcase_90 | AC | 172 ms
5,376 KB |
testcase_91 | AC | 169 ms
5,376 KB |
testcase_92 | AC | 171 ms
5,376 KB |
testcase_93 | AC | 167 ms
5,376 KB |
ソースコード
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); }