結果

問題 No.989 N×Mマス計算(K以上)
ユーザー sino
提出日時 2020-04-20 15:38:19
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 2,000 bytes
コンパイル時間 13,080 ms
コンパイル使用メモリ 379,864 KB
実行使用メモリ 7,484 KB
最終ジャッジ日時 2024-10-06 08:55:29
合計ジャッジ時間 14,146 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

fn main() {
    let (n, m, k) = read!(usize, usize, u64);
    let (op, mut b): (char, Vec<u64>) = {
        let buf = read!([String]);
        (
            buf[0].chars().next().unwrap(),
            buf[1..]
                .into_iter()
                .map(|e| e.parse::<u64>().unwrap())
                .collect(),
        )
    };
    let mut a = read!(u64; n);

    a.sort();
    b.sort();

    let mut lb = 0;
    let mut ub = m;
    let mut ans = 0;
    for row in 0..n {
        while (ub - lb) > 1 {
            let idx = (ub + lb - 1) / 2;
            let val = match op {
                '+' => a[row] + b[idx],
                '*' => a[row] * b[idx],
                _ => unreachable!(),
            };
            if val < k {
                lb = idx + 1;
            } else {
                ub = idx + 1;
            }
        }
        let idx = (ub + lb - 1) / 2;
        let val = match op {
            '+' => a[row] + b[idx],
            '*' => a[row] * b[idx],
            _ => unreachable!(),
        };

        if val < k {
            lb = idx + 1;
        }
        ans += m - lb;
        lb = 0;
    }

    println!("{}", ans);
}
0