結果

問題 No.1292 パタパタ三角形
ユーザー phsplsphspls
提出日時 2022-11-23 20:38:30
言語 Rust
(1.72.1)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,026 bytes
コンパイル時間 3,144 ms
コンパイル使用メモリ 191,800 KB
実行使用メモリ 9,400 KB
最終ジャッジ日時 2023-10-25 05:56:25
合計ジャッジ時間 4,270 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 15 ms
4,668 KB
testcase_08 AC 16 ms
4,668 KB
testcase_09 AC 27 ms
9,400 KB
testcase_10 AC 26 ms
9,400 KB
testcase_11 AC 27 ms
9,400 KB
testcase_12 AC 25 ms
9,400 KB
testcase_13 AC 26 ms
9,400 KB
testcase_14 AC 9 ms
4,348 KB
testcase_15 AC 9 ms
4,348 KB
testcase_16 AC 9 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `j`
  --> Main.rs:16:52
   |
16 |         let idx = pos.iter().enumerate().filter(|&(j, &c)| c == s[i]).nth(0).unwrap().0;
   |                                                    ^ help: if this is intentional, prefix it with an underscore: `_j`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

use std::collections::HashSet;


fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let s = s.trim().chars().collect::<Vec<_>>();

    let n = s.len();
    let mut pos = vec!['a', 'b', 'c'];
    let mut x = 0isize;
    let mut y = 0isize;
    let mut used = HashSet::new();
    used.insert((x, y));
    for i in 0..n {
        let idx = pos.iter().enumerate().filter(|&(j, &c)| c == s[i]).nth(0).unwrap().0;
        if i % 2 == 0 {
            match idx {
                0 => { y += 1; pos.swap(1, 2); },
                1 => { x += 1; pos.swap(2, 0); },
                2 => { x -= 1; pos.swap(0, 1); },
                _ => { unreachable!() },
            }
        } else {
            match idx {
                0 => { y -= 1; pos.swap(1, 2); },
                1 => { x -= 1; pos.swap(2, 0); },
                2 => { x += 1; pos.swap(0, 1); },
                _ => { unreachable!() },
            }
        }
        used.insert((x, y));
    }
    println!("{}", used.len());
}
0