結果
問題 |
No.2924 <===Super Spaceship String===>
|
ユーザー |
![]() |
提出日時 | 2024-10-12 17:57:48 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 1,550 bytes |
コンパイル時間 | 11,421 ms |
コンパイル使用メモリ | 379,032 KB |
実行使用メモリ | 7,240 KB |
最終ジャッジ日時 | 2024-10-16 17:56:08 |
合計ジャッジ時間 | 12,306 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 12 |
ソースコード
#![allow(non_snake_case, unused_must_use, unused_imports)] use std::io::{self, prelude::*}; fn main() { let (stdin, stdout) = (io::read_to_string(io::stdin()).unwrap(), io::stdout()); let (mut stdin, mut buffer) = (stdin.split_whitespace(), io::BufWriter::new(stdout.lock())); macro_rules! input { ($t: ty, $n: expr) => { (0..$n).map(|_| input!($t)).collect::<Vec<_>>() }; ($t: ty) => { stdin.next().unwrap().parse::<$t>().unwrap() }; } let S = input!(String).chars().collect::<Vec<_>>(); let mut stack = vec![]; for s in S { match s { '<' => { stack.push(('<', 1)); } '>' => { let l = stack.len(); if l >= 2 && stack[l - 1].0 == '=' && stack[l - 2].0 == '<' { stack.pop(); stack.pop(); } else { stack.push(('>', 1)); } } '=' => { if let Some((c, a)) = stack.pop() { if c == '=' { stack.push(('=', a + 1)); } else { stack.push((c, a)); stack.push(('=', 1)); } } else { stack.push(('=', 1)); } } _ => unreachable!(), } } let ans = stack.into_iter().map(|(_, c)| c).sum::<i32>(); writeln!(buffer, "{}", ans); }