結果
問題 | No.2453 Seat Allocation |
ユーザー | naut3 |
提出日時 | 2023-09-02 09:28:51 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 52 ms / 2,000 ms |
コード長 | 2,741 bytes |
コンパイル時間 | 13,745 ms |
コンパイル使用メモリ | 378,124 KB |
実行使用メモリ | 7,808 KB |
最終ジャッジ日時 | 2024-06-25 09:36:40 |
合計ジャッジ時間 | 13,781 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 32 ms
7,808 KB |
testcase_06 | AC | 13 ms
5,376 KB |
testcase_07 | AC | 8 ms
6,144 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 52 ms
7,680 KB |
testcase_10 | AC | 46 ms
7,808 KB |
testcase_11 | AC | 48 ms
7,680 KB |
testcase_12 | AC | 11 ms
5,376 KB |
testcase_13 | AC | 17 ms
5,376 KB |
testcase_14 | AC | 11 ms
5,376 KB |
testcase_15 | AC | 19 ms
5,376 KB |
testcase_16 | AC | 15 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 30 ms
5,376 KB |
testcase_19 | AC | 37 ms
6,400 KB |
testcase_20 | AC | 14 ms
5,376 KB |
testcase_21 | AC | 17 ms
5,376 KB |
testcase_22 | AC | 25 ms
5,376 KB |
testcase_23 | AC | 1 ms
5,376 KB |
testcase_24 | AC | 1 ms
5,376 KB |
ソースコード
#![allow(non_snake_case, unused_imports, unused_must_use)] use std::cmp::Reverse; 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!(usize, N); let B = input!(usize, M); let mut hq = std::collections::BinaryHeap::new(); for i in 0..N { hq.push((Ratio::new(A[i], B[0]), Reverse(i), 0)); } for _ in 0..M { let (_, i_rev, j) = hq.pop().unwrap(); let i = i_rev.0; if j + 1 < M { hq.push((Ratio::new(A[i], B[j + 1]), Reverse(i), j + 1)); } writeln!(out, "{}", i + 1); } } struct Ratio { a: usize, b: usize, } impl Ratio { fn new(a: usize, b: usize) -> Self { return Self { a: a, b: b }; } } impl PartialEq for Ratio { fn eq(&self, other: &Self) -> bool { let a1 = self.a; let b1 = self.b; let a2 = other.a; let b2 = other.b; a1 * b2 == a2 * b1 } } impl Eq for Ratio { fn assert_receiver_is_total_eq(&self) {} } impl PartialOrd for Ratio { fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { let a1 = self.a; let b1 = self.b; let a2 = other.a; let b2 = other.b; (a1 * b2).partial_cmp(&(a2 * b1)) } } impl Ord for Ratio { fn cmp(&self, other: &Self) -> std::cmp::Ordering { let a1 = self.a; let b1 = self.b; let a2 = other.a; let b2 = other.b; (a1 * b2).cmp(&(a2 * b1)) } } 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()) } } } }