結果
問題 | No.1412 Super Ryuo |
ユーザー |
![]() |
提出日時 | 2021-02-28 21:26:27 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 6,150 bytes |
コンパイル時間 | 12,979 ms |
コンパイル使用メモリ | 378,852 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-02 22:05:42 |
合計ジャッジ時間 | 13,865 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
ソースコード
//! # Bundled libraries//!//! - `mario v0.1.0` → `crate::mario` (source: local filesystem, license: **missing**)use mario::*;use std::io::*;fn main() {let mut io = MarIo::new_stdio();let (a, b, c, d) = read!(io: i64, i64, i64, i64);if a == c || b == d || (a - c).abs() + (b - d).abs() <= 3 {writeln!(io, "{}", 1).unwrap();} else {writeln!(io, "{}", 2).unwrap();}}// The following code was expanded by `cargo-equip`.#[allow(unused)]pub mod mario {pub use crate::read;use std::io;use std::io::{BufRead, BufReader, BufWriter, ErrorKind, Result, Write};pub mod token {use std::str::FromStr;pub trait Token {type Output;fn parse(s: &str) -> Self::Output;}impl<T: FromStr> Token for T {type Output = T;fn parse(s: &str) -> Self::Output {s.parse::<T>().unwrap_or_else(|_| panic!("Parse Error"))}}#[allow(non_camel_case_types)]pub struct usize1();impl Token for usize1 {type Output = usize;fn parse(s: &str) -> Self::Output {let i = s.parse::<usize>().unwrap_or_else(|_| panic!("Parse Error"));i.checked_sub(1).unwrap()}}#[allow(non_camel_case_types)]pub struct isize1();impl Token for isize1 {type Output = isize;fn parse(s: &str) -> Self::Output {let i = s.parse::<isize>().unwrap_or_else(|_| panic!("Parse Error"));i.checked_sub(1).unwrap()}}}use token::Token;fn read_until_whitespace<R: BufRead + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize> {let mut read = 0;loop {let (done, used) = {let available = match r.fill_buf() {Ok(n) => n,Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,Err(e) => return Err(e),};match available.iter().enumerate().find(|(_, x)| x.is_ascii_whitespace()){Some((i, _)) => {buf.extend_from_slice(&available[..=i]);(true, i + 1)}None => {buf.extend_from_slice(available);(false, available.len())}}};r.consume(used);read += used;if done || used == 0 {return Ok(read);}}}macro_rules! prim_method {($name:ident: $T:ty) => {pub fn $name(&mut self) -> $T {self.parse::<$T>()}};($name:ident) => {prim_method!($name: $name);};}macro_rules! prim_methods {($name:ident: $T:ty; $($rest:tt)*) => {prim_method!($name:$T);prim_methods!($($rest)*);};($name:ident; $($rest:tt)*) => {prim_method!($name);prim_methods!($($rest)*);};() => ()}// MARimo + IO -> MarIopub struct MarIo<I: BufRead, O: Write> {reader: I,writer: BufWriter<O>,}impl<I: BufRead, O: Write> MarIo<I, O> {pub fn new(reader: I, writer: O) -> Self {Self {reader,writer: BufWriter::new(writer),}}fn token(&mut self) -> String {let mut buf = Vec::new();loop {buf.clear();read_until_whitespace(&mut self.reader, &mut buf).expect("困ってしまいましたね。どうやら入力がうまくいかないようです。");let len = buf.len();match len {0 => panic!("もう入力終わってますよ。"),1 if buf[0].is_ascii_whitespace() => (),_ => {if buf[len - 1].is_ascii_whitespace() {buf.truncate(len - 1);}break;}}}unsafe { String::from_utf8_unchecked(buf) }}pub fn parse<T: Token>(&mut self) -> T::Output {T::parse(&self.token())}prim_methods! {u8; u16; u32; u64; u128; usize;i8; i16; i32; i64; i128; isize;f32; f64;char; string: String;}}// MarIo with stdin/outimpl MarIo<BufReader<io::Stdin>, io::Stdout> {pub fn new_stdio() -> Self {Self::new(BufReader::new(io::stdin()), io::stdout())}}// MarIo with stdinlock/stdoutlockimpl MarIo<io::StdinLock<'static>, io::StdoutLock<'static>> {pub unsafe fn new_stdinlock() -> Self {let stdin = Box::leak(Box::new(io::stdin()));let stdout = Box::leak(Box::new(io::stdout()));Self::new(stdin.lock(), stdout.lock())}}impl<I: BufRead, O: Write> Write for MarIo<I, O> {fn write(&mut self, buf: &[u8]) -> Result<usize> {self.writer.write(buf)}fn flush(&mut self) -> Result<()> {self.writer.flush()}}#[macro_export]macro_rules! read {($stdin:ident: [char]) => {$stdin.string().chars().collect::<Vec<_>>()};($stdin:ident: [u8]) => {$stdin.string().bytes().collect::<Vec<_>>()};($stdin:ident: [$($t:tt),*; $n:expr]) => {(0..$n).map(|_| ($(read!($stdin: $t)),*)).collect::<Vec<_>>()};($stdin:ident: $t:ty) => {$stdin.parse::<$t>()};($stdin:ident: $($t:ty),+) => {($(read!($stdin: $t)),*)};}}