結果

問題 No.1292 パタパタ三角形
ユーザー fukafukatanifukafukatani
提出日時 2020-11-20 21:42:45
言語 Rust
(1.77.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,907 bytes
コンパイル時間 1,744 ms
コンパイル使用メモリ 157,624 KB
実行使用メモリ 5,424 KB
最終ジャッジ日時 2023-09-30 19:05:09
合計ジャッジ時間 2,707 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 24 ms
5,412 KB
testcase_08 AC 24 ms
5,412 KB
testcase_09 AC 15 ms
5,396 KB
testcase_10 AC 16 ms
5,396 KB
testcase_11 AC 16 ms
5,412 KB
testcase_12 AC 5 ms
5,320 KB
testcase_13 AC 5 ms
5,420 KB
testcase_14 AC 18 ms
5,416 KB
testcase_15 AC 17 ms
5,424 KB
testcase_16 AC 17 ms
5,416 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: function `read_vec` is never used
  --> Main.rs:75:4
   |
75 | fn read_vec<T: std::str::FromStr>() -> Vec<T> {
   |    ^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

ソースコード

diff #

#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>()
        .chars()
        .map(|ch| ch.to_digit(36).unwrap() as usize - 10)
        .collect::<Vec<_>>();

    let mut state = (2, 0); // 0: a, 1: b, 2: c
    let mut cur = (0, 0);
    let mut entried = vec![(0, 0)];
    for ch in s {
        if ch == state.0 {
            if state.1 == 0 {
                cur.1 -= 1;
            } else {
                cur.1 += 1;
            }
        } else if state.0 == 2 {
            if ch == 1 {
                cur.0 += 1;
                state.0 = 0;
            } else {
                cur.0 -= 1;
                state.0 = 1;
            }
        } else if state.0 == 1 {
            if ch == 0 {
                cur.0 += 1;
                state.0 = 2;
            } else {
                cur.0 -= 1;
                state.0 = 0;
            }
        } else if state.0 == 0 {
            if ch == 2 {
                cur.0 += 1;
                state.0 = 1;
            } else {
                cur.0 -= 1;
                state.0 = 2;
            }
        }

        state.1 = 1 - state.1;
        entried.push(cur);
    }
    entried.sort();
    entried.dedup();
    // debug!(entried);
    println!("{}", entried.len());
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0