結果

問題 No.1292 パタパタ三角形
ユーザー phsplsphspls
提出日時 2022-11-17 00:12:51
言語 Rust
(1.77.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,063 bytes
コンパイル時間 2,108 ms
コンパイル使用メモリ 190,512 KB
実行使用メモリ 9,376 KB
最終ジャッジ日時 2023-10-17 21:31:25
合計ジャッジ時間 3,703 ms
ジャッジサーバーID
(参考情報)
judge14 / 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 0 ms
4,348 KB
testcase_07 AC 15 ms
4,644 KB
testcase_08 AC 14 ms
4,644 KB
testcase_09 AC 23 ms
9,376 KB
testcase_10 AC 23 ms
9,376 KB
testcase_11 AC 22 ms
9,376 KB
testcase_12 AC 23 ms
9,376 KB
testcase_13 AC 23 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:16:54
   |
16 |         let idx = lines.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 mut pos = HashSet::new();
    let mut up = false;
    let mut x = 0isize;
    let mut y = 0isize;
    pos.insert((x, y));
    let mut lines = vec!['a', 'b', 'c'];
    for &c in s.iter() {
        let idx = lines.iter().enumerate().filter(|&(i, &target)| target == c).nth(0).unwrap().0;
        if up {
            match idx {
                0 => { y -= 1; lines.swap(1, 2); },
                1 => { x -= 1; lines.swap(0, 2); },
                2 => { x += 1; lines.swap(0, 1); },
                _ => { unreachable!(); }
            }
        } else {
            match idx {
                0 => { y += 1; lines.swap(1, 2); },
                1 => { x += 1; lines.swap(0, 2); },
                2 => { x -= 1; lines.swap(0, 1); },
                _ => { unreachable!(); }
            }
        }
        pos.insert((x, y));
        up = !up;
    }
    println!("{}", pos.len());
}
0