結果

問題 No.649 ここでちょっとQK!
ユーザー phsplsphspls
提出日時 2022-12-25 14:08:48
言語 Rust
(1.77.0)
結果
AC  
実行時間 271 ms / 3,000 ms
コード長 1,153 bytes
コンパイル時間 11,839 ms
コンパイル使用メモリ 377,764 KB
実行使用メモリ 17,536 KB
最終ジャッジ日時 2024-04-29 19:49:02
合計ジャッジ時間 16,262 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 271 ms
16,000 KB
testcase_04 AC 61 ms
17,536 KB
testcase_05 AC 59 ms
17,408 KB
testcase_06 AC 59 ms
17,408 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 43 ms
9,728 KB
testcase_13 AC 45 ms
9,600 KB
testcase_14 AC 43 ms
9,600 KB
testcase_15 AC 46 ms
9,600 KB
testcase_16 AC 43 ms
9,600 KB
testcase_17 AC 49 ms
10,368 KB
testcase_18 AC 54 ms
11,136 KB
testcase_19 AC 61 ms
11,904 KB
testcase_20 AC 65 ms
12,800 KB
testcase_21 AC 68 ms
13,440 KB
testcase_22 AC 75 ms
14,208 KB
testcase_23 AC 77 ms
15,104 KB
testcase_24 AC 83 ms
15,872 KB
testcase_25 AC 87 ms
16,768 KB
testcase_26 AC 91 ms
17,280 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 39 ms
9,600 KB
testcase_31 AC 40 ms
9,728 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 0 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::{collections::BinaryHeap, cmp::Reverse};


fn main() {
    let mut qk = String::new();
    std::io::stdin().read_line(&mut qk).ok();
    let qk: Vec<usize> = qk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let q = qk[0];
    let k = qk[1];
    let queries = (0..q).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
            temp
        })
        .collect::<Vec<_>>();

    let mut targets = BinaryHeap::new();
    let mut rests = BinaryHeap::new();
    for v in queries.iter() {
        if v[0] == 1 {
            targets.push(v[1]);
            if targets.len() > k {
                rests.push(Reverse(targets.pop().unwrap()));
            }
        } else {
            if targets.len() == k {
                println!("{}", targets.pop().unwrap());
                if let Some(Reverse(val)) = rests.pop() {
                    targets.push(val);
                }
            } else {
                println!("-1");
            }
        }
    }
}
0