結果
| 問題 |
No.1806 Rotating Golem
|
| ユーザー |
Strorkis
|
| 提出日時 | 2022-01-14 21:41:02 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 6,803 bytes |
| コンパイル時間 | 14,288 ms |
| コンパイル使用メモリ | 377,924 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-20 08:47:00 |
| 合計ジャッジ時間 | 15,373 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
ソースコード
pub mod input {
pub trait Readable {
type Output;
fn read<R: std::io::BufRead>(r: &mut R) -> Self::Output;
}
macro_rules! impl_readable_for_int {
($($t:ty)*) => ($(impl Readable for $t {
type Output = $t;
#[inline]
fn read<R: std::io::BufRead>(r: &mut R) -> Self::Output {
let mut is_positive = true;
let mut is_empty = true;
let mut is_only_sign = true;
let mut result: Self::Output = 0;
loop {
let buf = match r.fill_buf() {
Ok(buf) => buf,
Err(e) if e.kind() == std::io::ErrorKind::Interrupted => continue,
Err(e) => panic!("{}", e),
};
let (done, used, mut buf) = match buf.iter().position(u8::is_ascii_whitespace) {
Some(i) => (i > 0 || !is_empty, i + 1, &buf[..i]),
None => (buf.is_empty(), buf.len(), buf),
};
if is_empty && buf.len() > 0 {
is_empty = false;
buf = match buf[0] {
b'+' => &buf[1..],
b'-' => {
is_positive = false;
&buf[1..]
}
_ => buf,
};
}
if buf.len() > 0 {
is_only_sign = false;
}
if is_positive {
for &c in buf {
let x = (c as char).to_digit(10).expect("InvalidDigit");
result = result.checked_mul(10).expect("PosOverflow");
result = result.checked_add(x as $t).expect("PosOverflow");
}
} else {
for &c in buf {
let x = (c as char).to_digit(10).expect("InvalidDigit");
result = result.checked_mul(10).expect("NegOverflow");
result = result.checked_sub(x as $t).expect("NegOverflow");
}
}
r.consume(used);
if done {
if is_empty {
panic!("Empty");
}
if is_only_sign {
panic!("InvalidDigit");
}
return result;
}
}
}
})*)
}
impl_readable_for_int! { i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize }
pub mod marker {
use super::Readable;
pub enum Usize1 {}
impl Readable for Usize1 {
type Output = usize;
#[inline]
fn read<R: std::io::BufRead>(r: &mut R) -> Self::Output {
usize::read(r).checked_sub(1).expect("NegOverflow")
}
}
pub enum Bytes {}
impl Readable for Bytes {
type Output = Vec<u8>;
#[inline]
fn read<R: std::io::BufRead>(r: &mut R) -> Self::Output {
let mut result = Vec::new();
loop {
let buf = match r.fill_buf() {
Ok(buf) => buf,
Err(e) if e.kind() == std::io::ErrorKind::Interrupted => continue,
Err(e) => panic!("{}", e),
};
let (done, used, buf) = match buf.iter().position(u8::is_ascii_whitespace) {
Some(i) => (i > 0 || !result.is_empty(), i + 1, &buf[..i]),
None => (buf.is_empty(), buf.len(), buf),
};
result.extend_from_slice(buf);
r.consume(used);
if done { return result; }
}
}
}
}
impl Readable for String {
type Output = String;
#[inline]
fn read<R: std::io::BufRead>(r: &mut R) -> Self::Output {
String::from_utf8(marker::Bytes::read(r)).unwrap()
}
}
macro_rules! impl_readable_for_float {
($($t:ty)*) => ($(impl Readable for $t {
type Output = $t;
#[inline]
fn read<R: std::io::BufRead>(r: &mut R) -> Self::Output {
String::read(r).parse().unwrap()
}
})*)
}
impl_readable_for_float! { f32 f64 }
macro_rules! impl_readable_for_tuple {
($head:ident, $($tail:ident),*) => {
impl<$head, $($tail),*> Readable for ($head, $($tail),*)
where
$head: Readable,
$($tail: Readable),*,
{
type Output = (
<$head as Readable>::Output,
$(<$tail as Readable>::Output),*,
);
#[inline]
fn read<R: std::io::BufRead>(r: &mut R) -> Self::Output {
(<$head>::read(r), $(<$tail>::read(r)),*)
}
}
impl_readable_for_tuple!($($tail),*);
};
($head:ident) => {};
}
impl_readable_for_tuple!(A, B, C, D, E, F, G, H, I, J);
#[macro_export]
macro_rules! read {
($r:expr, [$t:tt; $n:expr]) => {{
<[_; $n]>::try_from(read!($r, ($t; $n)).as_slice()).unwrap()
}};
($r:expr, ($t:tt)) => {
read!($r, ($t; read!($r, usize)))
};
($r:expr, ($t:tt; $n:expr)) => {
(0..$n).map(|_| read!($r, $t)).collect::<Vec<_>>()
};
($r:expr, $t:ty) => {
<$t>::read($r)
};
}
#[macro_export]
macro_rules! input {
($r:expr, $($($v:ident)* : $t:tt),* $(,)?) => {$(
let $($v)* = read!($r, $t);
)*};
}
}
use input::Readable;
fn f(s: &str) -> u8 {
match s {
"N" => 0,
"E" => 1,
"S" => 2,
"W" => 3,
_ => panic!(),
}
}
fn run<R: std::io::BufRead, W: std::io::Write>(reader: &mut R, _writer: &mut W) {
input! {
reader,
a: String,
b: String,
}
let x = f(&a);
let y = f(&b);
let ans = (y + 4 - x) % 4;
println!("{}", ans);
}
fn main() {
let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
let ref mut reader = std::io::BufReader::new(stdin.lock());
let ref mut writer = std::io::BufWriter::new(stdout.lock());
run(reader, writer);
}
Strorkis