結果

問題 No.1292 パタパタ三角形
ユーザー phsplsphspls
提出日時 2022-11-18 00:08:10
言語 Rust
(1.77.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,097 bytes
コンパイル時間 6,832 ms
コンパイル使用メモリ 183,732 KB
実行使用メモリ 9,376 KB
最終ジャッジ日時 2023-10-19 14:29:13
合計ジャッジ時間 2,681 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,644 KB
testcase_08 AC 15 ms
4,644 KB
testcase_09 AC 27 ms
9,376 KB
testcase_10 AC 27 ms
9,376 KB
testcase_11 AC 27 ms
9,376 KB
testcase_12 AC 26 ms
9,376 KB
testcase_13 AC 27 ms
9,376 KB
testcase_14 AC 8 ms
4,348 KB
testcase_15 AC 8 ms
4,348 KB
testcase_16 AC 8 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `i`
  --> Main.rs:17:56
   |
17 |         let idx = indices.iter().enumerate().filter(|&(i, &target)| target == c).nth(0).unwrap().0;
   |                                                        ^ help: if this is intentional, prefix it with an underscore: `_i`
   |
   = 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 result = HashSet::new();
    let mut x = 0isize;
    let mut y = 0isize;
    result.insert((x, y));
    let mut indices = vec!['a', 'b', 'c'];
    for i in 0..n {
        let c = s[i];
        let idx = indices.iter().enumerate().filter(|&(i, &target)| target == c).nth(0).unwrap().0;
        if i & 1 == 0 {
            match idx {
                0 => { y += 1; indices.swap(1, 2); },
                1 => { x += 1; indices.swap(2, 0); },
                2 => { x -= 1; indices.swap(0, 1); },
                _ => { unreachable!() },
            };
        } else {
            match idx {
                0 => { y -= 1; indices.swap(1, 2); },
                1 => { x -= 1; indices.swap(2, 0); },
                2 => { x += 1; indices.swap(0, 1); },
                _ => { unreachable!() },
            };
        }
        result.insert((x, y));
    }
    println!("{}", result.len());
}
0