結果

問題 No.2453 Seat Allocation
ユーザー nautnaut
提出日時 2023-09-01 22:32:19
言語 Rust
(1.77.0)
結果
MLE  
実行時間 -
コード長 2,472 bytes
コンパイル時間 4,008 ms
コンパイル使用メモリ 155,844 KB
実行使用メモリ 813,264 KB
最終ジャッジ日時 2023-09-01 22:32:27
合計ジャッジ時間 6,182 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#![allow(non_snake_case, unused_imports, unused_must_use)]
use std::io::{self, prelude::*};
use std::str;

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());

    macro_rules! input {
        ($T: ty) => {
            scan.token::<$T>()
        };
        ($T: ty, $N: expr) => {
            (0..$N).map(|_| scan.token::<$T>()).collect::<Vec<_>>()
        };
    }

    let N = input!(usize);
    let M = input!(usize);

    let A = input!(f64, N);
    let B = input!(f64, M);

    let mut low = 0 as f64;
    let mut high = (1 << 30) as f64;

    while high - low > 0.001 as f64 {
        let m = (low + high) / 2.0;

        let mut cnt = 0;

        for &a in A.iter() {
            if a / B[0] < m {
                continue;
            }

            let mut ok = 0;
            let mut ng = M;

            while ng - ok > 1 {
                let m2 = (ok + ng) / 2;

                if a / B[m2] < m {
                    ng = m2;
                } else {
                    ok = m2;
                }
            }

            cnt += ok + 1;
        }

        if cnt < M {
            high = m;
        } else {
            low = m;
        }
    }

    let mut ans = vec![];
    for i in 0..N {
        for j in 0..M {
            if A[i] / B[j] < low {
                break;
            }

            ans.push((A[i] / B[j], i));
        }
    }

    ans.sort_by_key(|&(_, i)| i);
    ans.sort_by_key(|&(v, _)| -(v as isize));
    for i in 0..M {
        writeln!(out, "{}", ans[i].1 + 1);
    }
}

struct Scanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: str::SplitWhitespace<'static>,
}
impl<R: BufRead> Scanner<R> {
    fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_whitespace(),
        }
    }
    fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace())
            }
        }
    }
}
0