結果

問題 No.1469 programing
ユーザー RheoTommyRheoTommy
提出日時 2021-04-09 21:38:01
言語 Rust
(1.72.1)
結果
AC  
実行時間 60 ms / 3,000 ms
コード長 3,708 bytes
コンパイル時間 5,424 ms
コンパイル使用メモリ 143,448 KB
実行使用メモリ 68,012 KB
最終ジャッジ日時 2023-09-07 10:21:12
合計ジャッジ時間 5,080 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 6 ms
6,796 KB
testcase_12 AC 5 ms
5,488 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 8 ms
8,452 KB
testcase_15 AC 6 ms
5,932 KB
testcase_16 AC 8 ms
8,440 KB
testcase_17 AC 60 ms
68,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

// # ファイル構成
// - use 宣言
// - lib モジュール
// - main 関数
// - basic モジュール
//
// 常に使うテンプレートライブラリは basic モジュール内にあります。
// 問題に応じて使うライブラリ lib モジュール内にコピペしています。
// ライブラリのコードはこちら → https://github.com/RheoTommy/at_coder
// Twitter はこちら → https://twitter.com/RheoTommy

use std::collections::*;
use std::io::{stdout, BufWriter, Write};

use crate::basic::*;
use crate::lib::*;

pub mod lib {
    pub fn rle<T: Eq + Clone>(s: &[T]) -> Vec<(T, usize)> {
        let mut res: Vec<(T, usize)> = vec![];
        for si in s {
            if res.is_empty() || &(res[res.len() - 1].0) != si {
                res.push((si.clone(), 1));
            } else {
                let l = res.len();
                let (_, k) = &mut res[l - 1];
                *k += 1;
            }
        }
        res
    }
}

fn main() {
    let mut io = IO::new();
    let s = io.next_chars().collect::<Vec<_>>();
    let s = rle(&s);
    io.println(s.iter().map(|(ci, _)| *ci).collect::<String>());
}

pub mod basic {
    pub const U_INF: u64 = (1 << 60) + (1 << 30);
    pub const I_INF: i64 = (1 << 60) + (1 << 30);

    pub struct IO {
        iter: std::str::SplitAsciiWhitespace<'static>,
        buf: std::io::BufWriter<std::io::StdoutLock<'static>>,
    }

    impl IO {
        pub fn new() -> Self {
            use std::io::*;
            let mut input = String::new();
            std::io::stdin().read_to_string(&mut input).unwrap();
            let input = Box::leak(input.into_boxed_str());
            let out = Box::new(stdout());
            IO {
                iter: input.split_ascii_whitespace(),
                buf: BufWriter::new(Box::leak(out).lock()),
            }
        }

        pub fn next_str(&mut self) -> &str {
            self.iter.next().unwrap()
        }

        pub fn next<T: std::str::FromStr>(&mut self) -> T
        where
            <T as std::str::FromStr>::Err: std::fmt::Debug,
        {
            self.iter.next().unwrap().parse().unwrap()
        }

        pub fn next_usize(&mut self) -> usize {
            self.next()
        }

        pub fn next_uint(&mut self) -> u64 {
            self.next()
        }

        pub fn next_int(&mut self) -> i64 {
            self.next()
        }

        pub fn next_float(&mut self) -> f64 {
            self.next()
        }

        pub fn next_chars(&mut self) -> std::str::Chars {
            self.next_str().chars()
        }

        pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T>
        where
            <T as std::str::FromStr>::Err: std::fmt::Debug,
        {
            (0..n).map(|_| self.next()).collect::<Vec<_>>()
        }

        pub fn print<T: std::fmt::Display>(&mut self, t: T) {
            use std::io::Write;
            write!(self.buf, "{}", t).unwrap();
        }

        pub fn println<T: std::fmt::Display>(&mut self, t: T) {
            self.print(t);
            self.print("\n");
        }

        pub fn print_iter<T: std::fmt::Display, I: Iterator<Item = T>>(
            &mut self,
            mut iter: I,
            sep: &str,
        ) {
            if let Some(v) = iter.next() {
                self.print(v);
                for vi in iter {
                    self.print(sep);
                    self.print(vi);
                }
            }
            self.print("\n");
        }

        pub fn flush(&mut self) {
            use std::io::Write;
            self.buf.flush().unwrap();
        }
    }
}
0