結果
| 問題 |
No.1460 Max of Min
|
| コンテスト | |
| ユーザー |
akakimidori
|
| 提出日時 | 2021-12-09 02:48:46 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 286 ms / 2,000 ms |
| コード長 | 1,911 bytes |
| コンパイル時間 | 14,562 ms |
| コンパイル使用メモリ | 378,704 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-12 00:55:43 |
| 合計ジャッジ時間 | 23,984 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 91 |
ソースコード
pub trait Kitamasa: Clone {
fn zero() -> Self;
fn one() -> Self;
fn add(&self, rhs: &Self) -> Self;
fn mul(&self, rhs: &Self) -> Self;
}
pub fn kitamasa_kth<T: Kitamasa>(c: &[T], mut k: usize) -> Vec<T> {
let n = c.len();
assert!(n > 0);
let mul = |a: &[T], b: &[T]| -> Vec<T> {
let mut x = vec![T::zero(); a.len() + b.len() - 1];
for (i, a) in a.iter().enumerate() {
for (x, b) in x[i..].iter_mut().zip(b) {
*x = x.add(&a.mul(b));
}
}
for i in (n..x.len()).rev() {
let v = x.pop().unwrap();
for (x, c) in x[(i - n)..].iter_mut().zip(c) {
*x = x.add(&v.mul(c));
}
}
x
};
let mut t = vec![T::one()];
let mut s = vec![T::zero(), T::one()];
while k > 0 {
if k & 1 == 1 {
t = mul(&t, &s);
}
s = mul(&s, &s);
k >>= 1;
}
t.resize(n, 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 Kitamasa 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 d = kitamasa_kth(&b, n);
let ans = a.into_iter().zip(d).fold(std::i64::MIN, |s, p| s.max(p.0.min(p.1)));
println!("{}", ans);
}
akakimidori