結果

問題 No.989 N×Mマス計算(K以上)
コンテスト
ユーザー elphe
提出日時 2026-02-09 17:53:27
言語 Rust
(1.93.0 + proconio + num + itertools)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,662 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,064 ms
コンパイル使用メモリ 207,792 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-02-09 17:53:31
合計ジャッジ時間 3,775 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

fn main() {
    let stdin = std::io::read_to_string(std::io::stdin().lock()).unwrap();
    let mut stdin = stdin.split_ascii_whitespace();

    let n: usize = stdin.next().unwrap().parse().unwrap();
    let m: usize = stdin.next().unwrap().parse().unwrap();
    let k: u32 = stdin.next().unwrap().parse().unwrap();
    let op: char = stdin.next().unwrap().parse().unwrap();
    let b: Vec<u32> = (0..m)
        .map(|_| stdin.next().unwrap().parse().unwrap())
        .collect();
    let a: Vec<u32> = (0..n)
        .map(|_| stdin.next().unwrap().parse().unwrap())
        .collect();

    use std::io::Write;
    std::io::stdout()
        .lock()
        .write_all(output(solve(k, op, a, b)).as_bytes())
        .unwrap();
}

fn solve(k: u32, op: char, mut a: Vec<u32>, mut b: Vec<u32>) -> u64 {
    a.sort_unstable();
    b.sort_unstable();
    let a = a;
    let b = b;

    let mut j = 0;
    a.len() as u64 * b.len() as u64
        - match op {
            '+' => a
                .into_iter()
                .rev()
                .map(|a| {
                    while j != b.len() && a + b[j] < k {
                        j += 1;
                    }
                    j as u64
                })
                .sum::<u64>(),
            '*' => a
                .into_iter()
                .rev()
                .map(|a| {
                    while j != b.len() && (a as u64 * b[j] as u64) < k as u64 {
                        j += 1;
                    }
                    j as u64
                })
                .sum::<u64>(),
            _ => unreachable!(),
        }
}

fn output(ans: u64) -> String {
    ans.to_string() + "\n"
}
0