結果

問題 No.2453 Seat Allocation
ユーザー haihamabossuhaihamabossu
提出日時 2023-09-01 23:23:26
言語 Rust
(1.77.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 2,666 bytes
コンパイル時間 928 ms
コンパイル使用メモリ 154,380 KB
実行使用メモリ 13,604 KB
最終ジャッジ日時 2023-09-07 15:37:46
合計ジャッジ時間 3,239 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 50 ms
13,604 KB
testcase_06 AC 22 ms
8,368 KB
testcase_07 AC 18 ms
9,268 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 69 ms
12,608 KB
testcase_10 AC 67 ms
12,716 KB
testcase_11 AC 65 ms
12,676 KB
testcase_12 AC 21 ms
8,436 KB
testcase_13 AC 26 ms
8,456 KB
testcase_14 AC 21 ms
8,432 KB
testcase_15 AC 31 ms
8,432 KB
testcase_16 AC 25 ms
8,064 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 45 ms
9,504 KB
testcase_19 AC 54 ms
12,264 KB
testcase_20 AC 21 ms
5,968 KB
testcase_21 AC 27 ms
6,480 KB
testcase_22 AC 38 ms
8,456 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

pub mod scanner {

    pub struct Scanner {
        buf: Vec<String>,
    }

    impl Scanner {
        pub fn new() -> Self {
            Self { buf: vec![] }
        }

        pub fn new_from(source: &str) -> Self {
            let source = String::from(source);
            let buf = Self::split(source);
            Self { buf }
        }

        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            loop {
                if let Some(x) = self.buf.pop() {
                    return x.parse().ok().expect("");
                }
                let mut source = String::new();
                std::io::stdin().read_line(&mut source).expect("");
                self.buf = Self::split(source);
            }
        }

        fn split(source: String) -> Vec<String> {
            source
                .split_whitespace()
                .rev()
                .map(String::from)
                .collect::<Vec<_>>()
        }
    }
}

use crate::scanner::Scanner;
use std::{collections::BinaryHeap, io::Write};

fn main() {
    let mut scanner = Scanner::new();
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let t: usize = 1;
    for _ in 0..t {
        solve(&mut scanner, &mut out);
    }
}

#[derive(PartialEq, Eq)]
struct P {
    a: usize,
    b: usize,
    i: usize,
    j: usize,
}

impl PartialOrd for P {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        let x = self.a * other.b;
        let y = other.a * self.b;
        if x == y {
            other.i.partial_cmp(&self.i)
        } else {
            x.partial_cmp(&y)
        }
    }
}

impl Ord for P {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        let x = self.a * other.b;
        let y = other.a * self.b;
        if x == y {
            other.i.cmp(&self.i)
        } else {
            x.cmp(&y)
        }
    }
}

fn solve(scanner: &mut Scanner, out: &mut std::io::BufWriter<std::io::StdoutLock>) {
    let n: usize = scanner.next();
    let m: usize = scanner.next();
    let a = (0..n).map(|_| scanner.next::<usize>()).collect::<Vec<_>>();
    let b = (0..m).map(|_| scanner.next::<usize>()).collect::<Vec<_>>();
    let mut que = BinaryHeap::new();
    for i in 0..n {
        que.push(P {
            a: a[i],
            b: b[0],
            i,
            j: 0,
        });
    }
    for _ in 0..m {
        let p = que.pop().unwrap();
        writeln!(out, "{}", p.i + 1).unwrap();
        if p.j < m - 1 {
            que.push(P {
                a: a[p.i],
                b: b[p.j + 1],
                i: p.i,
                j: p.j + 1,
            });
        }
    }
}
0