結果

問題 No.989 N×Mマス計算(K以上)
ユーザー tonyu0tonyu0
提出日時 2020-04-30 00:45:37
言語 Rust
(1.77.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,235 bytes
コンパイル時間 1,150 ms
コンパイル使用メモリ 148,124 KB
実行使用メモリ 4,716 KB
最終ジャッジ日時 2023-08-20 14:55:26
合計ジャッジ時間 2,158 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,504 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 11 ms
4,376 KB
testcase_11 AC 13 ms
4,376 KB
testcase_12 AC 12 ms
4,376 KB
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 16 ms
4,716 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 8 ms
4,380 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 6 ms
4,504 KB
testcase_19 AC 12 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn lower_bound<T: PartialOrd>(x: T, a: &Vec<T>) -> usize {
    let mut l: usize = 0;
    let mut r: usize = a.len();
    while r != l {
        let mid = (l + r) >> 1;
        if a[mid] < x {
            l = mid + 1;
        } else {
            r = mid;
        }
    }
    l
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let op: char = itr.next().unwrap().parse().unwrap();
    let mut b: Vec<usize> = (0..m)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    b.sort();

    let mut ans = 0;
    if op == '+' {
        for i in 0..n {
            ans += m;
            if k >= a[i] {
                ans -= lower_bound(k - a[i], &b);
            }
        }
    } else {
        for i in 0..n {
            ans += m - lower_bound((k + a[i] - 1) / a[i], &b);
        }
    }
    println!("{}", ans);
}
0