結果

問題 No.1285 ゴミ捨て
ユーザー StrorkisStrorkis
提出日時 2020-11-13 21:28:39
言語 Rust
(1.77.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 2,081 bytes
コンパイル時間 2,450 ms
コンパイル使用メモリ 166,192 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-19 07:12:41
合計ジャッジ時間 2,967 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 21 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 19 ms
4,380 KB
testcase_11 AC 17 ms
4,380 KB
testcase_12 AC 13 ms
4,376 KB
testcase_13 AC 13 ms
4,380 KB
testcase_14 AC 19 ms
4,376 KB
testcase_15 AC 14 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 8 ms
4,376 KB
testcase_20 AC 3 ms
4,384 KB
testcase_21 AC 6 ms
4,376 KB
testcase_22 AC 22 ms
4,376 KB
testcase_23 AC 22 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{BufRead, BufReader, BufWriter, Write};
use std::{str::FromStr, iter::FromIterator, fmt::Display};

pub struct ProconIo<'a> {
    pub reader: BufReader<std::io::StdinLock<'a>>,
    pub writer: BufWriter<std::io::StdoutLock<'a>>,
}

impl ProconIo<'_> {
    pub fn get_input(&mut self) -> String {
        let mut input = String::new();
        self.reader.read_line(&mut input).ok();
        input
    }

    pub fn read<T: FromStr>(&mut self) -> T {
        self.get_input().trim().parse().ok().unwrap()
    }

    pub fn read_col<T: FromStr, C: FromIterator<T>>(&mut self) -> C {
        self.get_input()
            .split_whitespace()
            .map(|x| x.parse().ok().unwrap())
            .collect()
    }

    pub fn read_chars<C: FromIterator<char>>(&mut self) -> C {
        self.get_input().trim().chars().collect()
    }

    pub fn writeln<T: Display>(&mut self, x: T) {
        writeln!(self.writer, "{}", x).ok();
    }

    pub fn writeln_col<C: IntoIterator>(&mut self, c: C)
    where
        C::Item: Display,
    {
        self.writeln(
            c.into_iter()
                .map(|x| x.to_string())
                .collect::<Vec<_>>()
                .join(" ")
        )
    }
}

#[allow(unused_macros)]
macro_rules! read_tuple {
    ( $io:expr, $( $t:ty ),* ) => {{
        let input = $io.get_input();
        let mut iter = input.split_whitespace();
        ( $( iter.next().unwrap().parse::<$t>().unwrap() ),* )
    }};
}

fn solve(io: &mut ProconIo) {
    let n: usize = io.read();
    let mut a: Vec<i32> = (0..n).map(|_| io.read()).collect();

    a.sort();
    let mut set = std::collections::BTreeSet::new();
    for a in a.into_iter().rev() {
        if let Some(&val) = set.range((a + 2)..).next() {
            set.remove(&val);
        }
        set.insert(a);
    }
    io.writeln(set.len());
}

fn main() {
    let stdin = std::io::stdin();
    let stdout = std::io::stdout();
    let mut io = ProconIo {
        reader: BufReader::new(stdin.lock()),
        writer: BufWriter::new(stdout.lock()),
    };
    solve(&mut io);
}
0