結果
問題 | No.2453 Seat Allocation |
ユーザー |
![]() |
提出日時 | 2023-09-01 22:43:15 |
言語 | Rust (1.83.0 + proconio) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,807 bytes |
コンパイル時間 | 15,739 ms |
コンパイル使用メモリ | 377,448 KB |
実行使用メモリ | 816,512 KB |
最終ジャッジ日時 | 2025-01-03 10:13:36 |
合計ジャッジ時間 | 22,326 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 WA * 2 MLE * 2 |
ソースコード
#![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] <= high {break;}ans.push((A[i] / B[j], i));}}while ans.len() < M {for i in 0..N {for j in 0..M {if A[i] / B[j] < high && A[i] / B[j] >= low {ans.push((A[i] / B[j], i));}if A[i] / B[j] < low {break;}}}}ans.sort_by_key(|&(_, i)| i);ans.sort_by(|&a, b| b.0.partial_cmp(&a.0).unwrap());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())}}}}