結果

問題 No.1460 Max of Min
ユーザー akakimidoriakakimidori
提出日時 2021-04-03 05:24:53
言語 Rust
(1.77.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,826 bytes
コンパイル時間 2,419 ms
コンパイル使用メモリ 155,276 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 19:39:58
合計ジャッジ時間 10,273 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 163 ms
4,376 KB
testcase_04 AC 164 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 164 ms
4,376 KB
testcase_07 AC 163 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 180 ms
4,376 KB
testcase_11 AC 164 ms
4,376 KB
testcase_12 AC 15 ms
4,376 KB
testcase_13 AC 63 ms
4,376 KB
testcase_14 AC 22 ms
4,376 KB
testcase_15 AC 11 ms
4,380 KB
testcase_16 AC 54 ms
4,376 KB
testcase_17 AC 29 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 31 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 32 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 35 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 65 ms
4,376 KB
testcase_27 AC 12 ms
4,376 KB
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 35 ms
4,380 KB
testcase_30 AC 50 ms
4,376 KB
testcase_31 AC 31 ms
4,380 KB
testcase_32 AC 9 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 7 ms
4,376 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 6 ms
4,376 KB
testcase_38 AC 4 ms
4,376 KB
testcase_39 AC 4 ms
4,376 KB
testcase_40 AC 5 ms
4,376 KB
testcase_41 AC 3 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 14 ms
4,380 KB
testcase_44 AC 25 ms
4,380 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 10 ms
4,380 KB
testcase_47 AC 12 ms
4,376 KB
testcase_48 AC 28 ms
4,376 KB
testcase_49 AC 20 ms
4,376 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 14 ms
4,380 KB
testcase_52 AC 4 ms
4,376 KB
testcase_53 AC 4 ms
4,376 KB
testcase_54 AC 6 ms
4,380 KB
testcase_55 AC 29 ms
4,376 KB
testcase_56 AC 5 ms
4,376 KB
testcase_57 AC 24 ms
4,380 KB
testcase_58 AC 165 ms
4,376 KB
testcase_59 AC 18 ms
4,380 KB
testcase_60 AC 22 ms
4,376 KB
testcase_61 AC 7 ms
4,376 KB
testcase_62 AC 8 ms
4,376 KB
testcase_63 AC 1 ms
4,376 KB
testcase_64 AC 1 ms
4,376 KB
testcase_65 AC 34 ms
4,376 KB
testcase_66 AC 7 ms
4,380 KB
testcase_67 AC 3 ms
4,376 KB
testcase_68 AC 24 ms
4,380 KB
testcase_69 AC 20 ms
4,380 KB
testcase_70 AC 14 ms
4,380 KB
testcase_71 AC 31 ms
4,376 KB
testcase_72 AC 6 ms
4,380 KB
testcase_73 AC 6 ms
4,380 KB
testcase_74 AC 6 ms
4,380 KB
testcase_75 AC 5 ms
4,380 KB
testcase_76 AC 5 ms
4,376 KB
testcase_77 AC 5 ms
4,376 KB
testcase_78 AC 4 ms
4,376 KB
testcase_79 AC 6 ms
4,376 KB
testcase_80 AC 5 ms
4,376 KB
testcase_81 AC 4 ms
4,376 KB
testcase_82 AC 5 ms
4,380 KB
testcase_83 AC 4 ms
4,376 KB
testcase_84 AC 166 ms
4,376 KB
testcase_85 AC 160 ms
4,380 KB
testcase_86 AC 167 ms
4,380 KB
testcase_87 AC 155 ms
4,376 KB
testcase_88 AC 160 ms
4,376 KB
testcase_89 AC 165 ms
4,376 KB
testcase_90 AC 154 ms
4,380 KB
testcase_91 AC 159 ms
4,380 KB
testcase_92 AC 182 ms
4,376 KB
testcase_93 AC 170 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
}

pub fn kitamasa<T, F, G>(a: &[T], b: &[T], mut n: usize, zero: T, one: T, add: F, mul: G) -> T
where
    T: Clone,
    F: Fn(&T, &T) -> T,
    G: Fn(&T, &T) -> T,
{
    assert!(a.len() == b.len() && a.len() > 0);
    let k = a.len();
    let calc = |x: &[T], y: &[T]| -> Vec<T> {
        let mut z = vec![zero.clone(); x.len() + y.len() - 1];
        for (i, x) in x.iter().enumerate() {
            for (z, y) in z[i..].iter_mut().zip(y.iter()) {
                *z = add(z, &mul(x, y));
            }
        }
        for i in (k..z.len()).rev() {
            let p = z.pop().unwrap();
            for (z, b) in z[(i - k)..].iter_mut().zip(b.iter()) {
                *z = add(z, &mul(&p, b));
            }
        }
        z
    };
    let mut t = vec![zero.clone()];
    let mut s = vec![zero.clone()];
    t[0] = one.clone();
    if k > 1 {
        s.push(one);
    } else {
        s[0] = b[0].clone();
    }
    while n > 0 {
        if n & 1 == 1 {
            t = calc(&t, &s);
        }
        s = calc(&s, &s);
        n >>= 1;
    }
    let mut ans = zero;
    for (t, a) in t.iter().zip(a.iter()) {
        ans = add(&ans, &mul(t, a));
    }
    ans
}

fn main() {
    let (n, a, b) = read();
    let inf = 10i64.pow(18) + 1;
    let ans = kitamasa(&a, &b, n, -inf, inf, |a, b| std::cmp::max(*a, *b), |a, b| std::cmp::min(*a, *b));
    println!("{}", ans);
}
0