結果
| 問題 |
No.1292 パタパタ三角形
|
| コンテスト | |
| ユーザー |
Strorkis
|
| 提出日時 | 2020-11-20 22:00:34 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 2,000 ms |
| コード長 | 3,020 bytes |
| コンパイル時間 | 12,915 ms |
| コンパイル使用メモリ | 390,516 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-23 13:00:40 |
| 合計ジャッジ時間 | 13,977 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
use std::io::{BufRead, BufWriter, Write, StdinLock, StdoutLock};
fn input(stdin: &mut StdinLock) -> String {
let mut input = String::new();
stdin.read_line(&mut input).ok();
input
}
macro_rules! read {
($stdin:expr, [$t:tt; $n:expr]) => {
(0..$n).map(|_| read!($stdin, $t)).collect::<Vec<_>>()
};
($stdin:expr, [$t:tt]) => {
input($stdin)
.split_whitespace()
.map(|x| parse!(x, $t))
.collect::<Vec<_>>()
};
($stdin:expr, ($($t:tt),*)) => {
{
let input = input($stdin);
let mut iter = input.split_whitespace();
( $( parse!(iter.next().unwrap(), $t) ),* )
}
};
($stdin:expr, $t:tt) => {
parse!(input($stdin).trim(), $t)
};
}
macro_rules! parse {
($s:expr, chars) => {
$s.chars().collect::<Vec<_>>()
};
($s:expr, usize1) => {
parse!($s, usize) - 1
};
($s:expr, $t:ty) => {
$s.parse::<$t>().unwrap()
}
}
trait ProconWrite {
fn writeln<T: std::fmt::Display>(&mut self, x: T);
fn writeln_iter<I: Iterator>(&mut self, iter: I)
where
I::Item: std::fmt::Display
{
self.writeln(
iter.map(|x| x.to_string()).collect::<Vec<_>>().join(" ")
);
}
}
impl ProconWrite for BufWriter<StdoutLock<'_>> {
fn writeln<T: std::fmt::Display>(&mut self, x: T) {
writeln!(self, "{}", x).ok();
}
}
fn solve(stdin: &mut StdinLock, writer: &mut BufWriter<StdoutLock>) {
let s = read!(stdin, String);
let f = |x: i32| {
let res = x % 6;
if res < 0 { res + 6 } else { res }
};
let (mut x, mut y): (i32, i32) = (0, 0);
let mut set = std::collections::HashSet::new();
set.insert((x, y));
for c in s.chars() {
if c == 'a' {
match f(x) {
0 => x -= 1,
1 => if y % 2 == 0 { y += 1; } else { y -= 1; },
2 => x += 1,
3 => x -= 1,
4 => if y % 2 == 0 { y -= 1; } else { y += 1; },
_ => x += 1,
}
} else if c == 'b' {
match f(x) {
0 => x += 1,
1 => x -= 1,
2 => if y % 2 == 0 { y -= 1; } else { y += 1; },
3 => x += 1,
4 => x -= 1,
_ => if y % 2 == 0 { y += 1; } else { y -= 1; },
}
} else {
match f(x) {
0 => if y % 2 == 0 { y -= 1; } else { y += 1; },
1 => x += 1,
2 => x -= 1,
3 => if y % 2 == 0 { y += 1; } else { y -= 1; },
4 => x += 1,
_ => x -= 1,
}
}
set.insert((x, y));
}
writer.writeln(set.len());
}
fn main() {
let stdin = std::io::stdin();
let mut stdin = stdin.lock();
let stdout = std::io::stdout();
let mut writer = BufWriter::new(stdout.lock());
solve(&mut stdin, &mut writer);
}
Strorkis