結果

問題 No.989 N×Mマス計算(K以上)
ユーザー cra77756176
提出日時 2022-12-24 19:50:15
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,056 bytes
コンパイル時間 14,395 ms
コンパイル使用メモリ 401,596 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-18 05:35:32
合計ジャッジ時間 12,353 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut xx = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut xx).ok();
    let xx: Vec<&str> = xx.split_whitespace().collect();

    let m: usize = xx[1].parse().unwrap();
    let k: u64 = xx[2].parse().unwrap();
    let mut bb: Vec<u64> = xx[4..4 + m].iter().map(|&s| s.parse().unwrap()).collect();
    let mut aa: Vec<u64> = xx[4 + m..].iter().map(|&s| s.parse().unwrap()).collect();

    let op = match xx.get(3) {
        Some(&"+") => |a, b| a + b,
        Some(&"*") => |a, b| a * b,
        _ => unreachable!(),
    };

    aa.sort_unstable();
    bb.sort_unstable();
    aa.reverse();
    bb.reverse();

    let mut answer = 0;
    let mut left = 0;
    let mut right = bb.len();
    for &a in &aa {
        while left < right {
            let center = (left + right) / 2;
            if op(a, bb[center]) >= k {
                left = center + 1;
            } else {
                right = center;
            }
        }
        answer += left;
        left = 0;
    }

    println!("{answer}");
}
0