結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー koba-e964koba-e964
提出日時 2021-11-23 17:01:28
言語 Rust
(1.77.0)
結果
AC  
実行時間 65 ms / 1,000 ms
コード長 2,763 bytes
コンパイル時間 1,819 ms
コンパイル使用メモリ 154,212 KB
実行使用メモリ 11,916 KB
最終ジャッジ日時 2023-09-07 19:49:46
合計ジャッジ時間 4,802 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
11,912 KB
testcase_01 AC 62 ms
11,904 KB
testcase_02 AC 12 ms
6,764 KB
testcase_03 AC 11 ms
6,744 KB
testcase_04 AC 11 ms
6,724 KB
testcase_05 AC 11 ms
6,716 KB
testcase_06 AC 11 ms
6,744 KB
testcase_07 AC 11 ms
6,668 KB
testcase_08 AC 8 ms
4,424 KB
testcase_09 AC 12 ms
6,672 KB
testcase_10 AC 12 ms
6,764 KB
testcase_11 AC 11 ms
6,724 KB
testcase_12 AC 57 ms
11,652 KB
testcase_13 AC 61 ms
11,600 KB
testcase_14 AC 62 ms
11,756 KB
testcase_15 AC 60 ms
11,372 KB
testcase_16 AC 63 ms
11,580 KB
testcase_17 AC 58 ms
11,572 KB
testcase_18 AC 58 ms
11,524 KB
testcase_19 AC 58 ms
11,752 KB
testcase_20 AC 59 ms
11,560 KB
testcase_21 AC 59 ms
11,472 KB
testcase_22 AC 65 ms
11,916 KB
testcase_23 AC 11 ms
6,740 KB
testcase_24 AC 11 ms
6,724 KB
testcase_25 AC 11 ms
6,756 KB
権限があれば一括ダウンロードができます

ソースコード

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: i32,
        xab: [(usize, usize, usize); n],
    }
    const W: usize = 100_100;
    let mut ans = n as i32;
    let mut aidd = vec![vec![]; W];
    let mut two = 0;
    let mut three = 0;
    let mut freq = vec![[0i32; 6]; W];
    let mut pos = 0;
    for i in 0..n {
        let (x, a, b) = xab[i];
        aidd[a].push(i);
        if x >= 2 {
            three += 1;
        }
        if x == 1 {
            two += 1;
        }
        freq[b][x + 1] += 1;
    }
    for sa in (0..W).rev() {
        if sa <= 10 {
            eprintln!("{} => {:?}", sa, &freq[..10]);
            eprintln!("two = {}, three = {}", two, three);
        }
        for &idx in &aidd[sa] {
            let (x, _a, b) = xab[idx];
            let nx = x + if pos <= b { 1 } else { 0 };
            freq[b][nx] -= 1;
            freq[b][nx + 1] += 1;
            match nx {
                1 => two += 1,
                2 => {
                    two -= 1;
                    three += 1;
                }
                _ => {}
            }
        }
        while pos < W && two + three >= m {
            if two + three - freq[pos][2] >= m {
                three -= freq[pos][3];
                two += freq[pos][3] - freq[pos][2];
                for j in 0..5 {
                    freq[pos][j] = freq[pos][j + 1];
                }
                pos += 1;
            } else {
                break;
            }
        }
        if two + three >= m {
            ans = min(ans, three);
        }
        if sa <= 10 {
            eprintln!("{} => {:?}", sa, &freq[..10]);
            eprintln!("two = {}, three = {}, pos = {}\n", two, three, pos);
        }
    }
    println!("{}", ans);
}
0