結果

問題 No.1460 Max of Min
ユーザー koba-e964koba-e964
提出日時 2022-01-04 01:13:16
言語 Rust
(1.77.0)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 2,065 bytes
コンパイル時間 834 ms
コンパイル使用メモリ 163,456 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 15:42:45
合計ジャッジ時間 11,072 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 229 ms
5,376 KB
testcase_04 AC 231 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 227 ms
5,376 KB
testcase_07 AC 225 ms
5,376 KB
testcase_08 AC 0 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 276 ms
5,376 KB
testcase_11 AC 228 ms
5,376 KB
testcase_12 AC 26 ms
5,376 KB
testcase_13 AC 118 ms
5,376 KB
testcase_14 AC 38 ms
5,376 KB
testcase_15 AC 18 ms
5,376 KB
testcase_16 AC 101 ms
5,376 KB
testcase_17 AC 54 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 53 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 7 ms
5,376 KB
testcase_22 AC 57 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 68 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 114 ms
5,376 KB
testcase_27 AC 19 ms
5,376 KB
testcase_28 AC 6 ms
5,376 KB
testcase_29 AC 64 ms
5,376 KB
testcase_30 AC 98 ms
5,376 KB
testcase_31 AC 56 ms
5,376 KB
testcase_32 AC 42 ms
5,376 KB
testcase_33 AC 12 ms
5,376 KB
testcase_34 AC 23 ms
5,376 KB
testcase_35 AC 9 ms
5,376 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 26 ms
5,376 KB
testcase_38 AC 35 ms
5,376 KB
testcase_39 AC 17 ms
5,376 KB
testcase_40 AC 13 ms
5,376 KB
testcase_41 AC 9 ms
5,248 KB
testcase_42 AC 6 ms
5,376 KB
testcase_43 AC 35 ms
5,376 KB
testcase_44 AC 62 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 25 ms
5,376 KB
testcase_47 AC 34 ms
5,376 KB
testcase_48 AC 68 ms
5,376 KB
testcase_49 AC 43 ms
5,376 KB
testcase_50 AC 3 ms
5,376 KB
testcase_51 AC 33 ms
5,376 KB
testcase_52 AC 8 ms
5,376 KB
testcase_53 AC 29 ms
5,376 KB
testcase_54 AC 53 ms
5,376 KB
testcase_55 AC 80 ms
5,376 KB
testcase_56 AC 54 ms
5,376 KB
testcase_57 AC 142 ms
5,376 KB
testcase_58 AC 266 ms
5,376 KB
testcase_59 AC 81 ms
5,376 KB
testcase_60 AC 67 ms
5,376 KB
testcase_61 AC 48 ms
5,376 KB
testcase_62 AC 46 ms
5,376 KB
testcase_63 AC 30 ms
5,376 KB
testcase_64 AC 35 ms
5,376 KB
testcase_65 AC 80 ms
5,376 KB
testcase_66 AC 48 ms
5,376 KB
testcase_67 AC 37 ms
5,376 KB
testcase_68 AC 67 ms
5,376 KB
testcase_69 AC 68 ms
5,376 KB
testcase_70 AC 59 ms
5,376 KB
testcase_71 AC 75 ms
5,376 KB
testcase_72 AC 46 ms
5,376 KB
testcase_73 AC 46 ms
5,376 KB
testcase_74 AC 48 ms
5,376 KB
testcase_75 AC 46 ms
5,376 KB
testcase_76 AC 43 ms
5,376 KB
testcase_77 AC 50 ms
5,376 KB
testcase_78 AC 41 ms
5,376 KB
testcase_79 AC 54 ms
5,376 KB
testcase_80 AC 48 ms
5,376 KB
testcase_81 AC 41 ms
5,376 KB
testcase_82 AC 48 ms
5,376 KB
testcase_83 AC 46 ms
5,376 KB
testcase_84 AC 240 ms
5,376 KB
testcase_85 AC 234 ms
5,376 KB
testcase_86 AC 230 ms
5,376 KB
testcase_87 AC 232 ms
5,376 KB
testcase_88 AC 241 ms
5,376 KB
testcase_89 AC 248 ms
5,376 KB
testcase_90 AC 223 ms
5,376 KB
testcase_91 AC 230 ms
5,376 KB
testcase_92 AC 261 ms
5,376 KB
testcase_93 AC 234 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

const INF: i64 = 1 << 60;

fn mul(a1: &[i64], a2: &[i64], b: &[i64]) -> Vec<i64> {
    let k = a1.len();
    let mut out = vec![-INF; 2 * k];
    for i in 0..k {
        for j in 0..k {
            out[i + j] = max(out[i + j], min(a1[i], a2[j]));
        }
    }
    for i in (k..2 * k).rev() {
        for j in 0..k {
            out[i - k + j] = max(out[i - k + j], min(b[j], out[i]));
        }
    }
    out.truncate(k);
    out
}

fn pow(a: &[i64], mut e: i64, b: &[i64]) -> Vec<i64> {
    let k = a.len();
    let mut prod = vec![-INF; k];
    prod[0] = INF;
    let mut cur = a.to_vec();
    while e > 0 {
        if e % 2 == 1 {
            prod = mul(&prod, &cur, b);
        }
        cur = mul(&cur, &cur, b);
        e /= 2;
    }
    prod
}


fn main() {
    input! {
        k: usize, n: i64,
        a: [i64; k],
        b: [i64; k],
    }
    let mut x = vec![-INF; k];
    if k > 1 {
        x[1] = INF;
    } else {
        x[0] = b[0];
    }
    let s = pow(&x, n, &b);
    let mut ans = -INF;
    for i in 0..k {
        ans = max(ans, min(s[i], a[i]));
    }
    println!("{}", ans);
}
0