結果

問題 No.1412 Super Ryuo
ユーザー marimo_marimo_
提出日時 2021-02-28 21:26:27
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 6,150 bytes
コンパイル時間 1,570 ms
コンパイル使用メモリ 174,704 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-12 10:25:11
合計ジャッジ時間 1,862 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//! # 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 -> MarIo
    pub 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/out
    impl MarIo<BufReader<io::Stdin>, io::Stdout> {
        pub fn new_stdio() -> Self {
            Self::new(BufReader::new(io::stdin()), io::stdout())
        }
    }

    // MarIo with stdinlock/stdoutlock
    impl 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)),*)
        };
    }
}
0