結果
| 問題 |
No.2453 Seat Allocation
|
| コンテスト | |
| ユーザー |
naut3
|
| 提出日時 | 2023-09-02 09:28:51 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 2,000 ms |
| コード長 | 2,741 bytes |
| コンパイル時間 | 11,447 ms |
| コンパイル使用メモリ | 389,128 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 01:48:37 |
| 合計ジャッジ時間 | 13,381 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#![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())
}
}
}
}
naut3