結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー koba-e964koba-e964
提出日時 2021-11-23 16:18:40
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,651 bytes
コンパイル時間 1,482 ms
コンパイル使用メモリ 156,564 KB
実行使用メモリ 11,976 KB
最終ジャッジ日時 2023-09-07 19:00:21
合計ジャッジ時間 4,586 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
11,916 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 52 ms
11,748 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 50 ms
11,524 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 61 ms
11,976 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    input! {
        n: usize, m: usize,
        xab: [(usize, usize, usize); n],
    }
    const W: usize = 100_100;
    let mut ans = n;
    let mut aidd = vec![vec![]; W];
    let mut two = 0;
    let mut three = 0;
    let mut freq = vec![[0; 3]; W];
    let mut pos = 0;
    for i in 0..n {
        let (x, a, b) = xab[i];
        aidd[a].push(i);
        if x == 3 {
            three += 1;
        }
        if x == 2 {
            two += 1;
        }
        if x <= 2 {
            freq[b][x] += 1;
        }
    }
    for sa in (0..W).rev() {
        for &idx in &aidd[sa] {
            let (x, _a, b) = xab[idx];
            let nx = x + if pos >= b { 1 } else { 0 };
            if nx <= 2 {
                freq[b][x] -= 1;
                if nx <= 1 {
                    freq[b][nx + 1] += 1;
                }
            }
            if pos >= b {
                match x {
                    1 => two += 1,
                    2 => {
                        two -= 1;
                        three += 1;
                    }
                    _ => {}
                }
            }
        }
        if pos < W && two + three >= m {
            if two + three - freq[pos][1] >= m {
                three += freq[pos][2];
                two += freq[pos][1] - freq[pos][2];
                for j in (0..2).rev() {
                    freq[pos][j + 1] = freq[pos][j];
                }
                pos += 1;
            } else {
                break;
            }
        }
        if two + three >= m {
            ans = min(ans, three);
        }
    }
    println!("{}", ans);
}
0