結果

問題 No.1280 Beyond C
ユーザー cympfhcympfh
提出日時 2020-11-06 21:28:19
言語 Rust
(1.72.1)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 4,272 bytes
コンパイル時間 883 ms
コンパイル使用メモリ 151,800 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2023-09-29 18:11:36
合計ジャッジ時間 2,380 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 27 ms
7,628 KB
testcase_16 AC 23 ms
7,304 KB
testcase_17 AC 26 ms
7,744 KB
testcase_18 AC 33 ms
12,800 KB
testcase_19 AC 29 ms
12,752 KB
testcase_20 AC 51 ms
12,536 KB
testcase_21 AC 50 ms
12,484 KB
testcase_22 AC 51 ms
12,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! trace {
    ($x:expr) => {
        #[cfg(debug_assertions)]
        eprintln!(">>> {} = {:?}", stringify!($x), $x)
    };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! flush {
    () => {
        std::io::stdout().flush().unwrap();
    };
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

// @algorithm/binary_search
pub trait Integer
where
    Self: std::marker::Sized,
{
    fn close(range: std::ops::Range<Self>) -> bool;
    fn middle(range: std::ops::Range<Self>) -> Self;
}
macro_rules! define_integer {
    ($type:ty, $range:ident, $close_condition:expr, $middle_point:expr) => {
        impl Integer for $type {
            fn close($range: std::ops::Range<Self>) -> bool {
                $close_condition
            }
            fn middle($range: std::ops::Range<Self>) -> Self {
                $middle_point
            }
        }
    };
}
define_integer!(usize, r, r.start + 1 >= r.end, (r.start + r.end) / 2);
define_integer!(u32, r, r.start + 1 >= r.end, (r.start + r.end) / 2);
define_integer!(u64, r, r.start + 1 >= r.end, (r.start + r.end) / 2);
define_integer!(u128, r, r.start + 1 >= r.end, (r.start + r.end) / 2);
define_integer!(i32, r, r.start + 1 >= r.end, (r.start + r.end) / 2);
define_integer!(i64, r, r.start + 1 >= r.end, (r.start + r.end) / 2);
define_integer!(i128, r, r.start + 1 >= r.end, (r.start + r.end) / 2);
define_integer!(
    f32,
    r,
    r.start + 0.00000001 >= r.end,
    (r.start + r.end) / 2.0
);
define_integer!(
    f64,
    r,
    r.start + 0.00000001 >= r.end,
    (r.start + r.end) / 2.0
);

// the minimum index in range s.t. prop holds
pub fn binsearch<X: Integer + Copy>(range: std::ops::Range<X>, prop: &dyn Fn(X) -> bool) -> X {
    if prop(range.start) {
        range.start
    } else {
        let mut left = range.start;
        let mut right = range.end;
        while !X::close(left..right) {
            let mid = X::middle(left..right);
            if prop(mid) {
                right = mid;
            } else {
                left = mid;
            }
        }
        right
    }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let m: usize = sc.cin();
    let c: u128 = sc.cin();
    let mut a: Vec<u128> = sc.vec(n);
    let mut b: Vec<u128> = sc.vec(m);
    a.sort();
    b.sort();
    let mut q = 0; // for beyond c
    for &x in a.iter() {
        let j = binsearch(0..m, &|i| x * b[i] > c);
        q += m - j;
    }
    put!(q as f64 / (n * m) as f64);
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}
0