結果

問題 No.24 数当てゲーム
ユーザー Yuzu MashiroYuzu Mashiro
提出日時 2021-04-06 13:36:02
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,291 bytes
コンパイル時間 1,515 ms
コンパイル使用メモリ 160,764 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-31 01:15:17
合計ジャッジ時間 2,318 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashSet;

fn _read() -> Vec<(bool, Vec<i8>)> {
    let mut ret: Vec<(bool, Vec<i8>)> = Vec::new();

    let mut _s = String::new();
    std::io::stdin().read_line(&mut _s).ok();

    loop {
        let mut _s = String::new();
        let _len = std::io::stdin().read_line(&mut _s).ok();
        if _len.unwrap() == 0 {
            break;
        }

        let mut _v: Vec<String> = _s
            .split_ascii_whitespace()
            .map(|e| e.trim().to_string())
            .collect();
        let _item: (bool, Vec<i8>) = (
            _v.pop().unwrap() == "YES",
            _v.iter().map(|e| e.trim().parse().ok().unwrap()).collect(),
        );

        ret.push(_item);
    }

    ret
}

fn calc(data: Vec<(bool, Vec<i8>)>) -> i8 {
    let mut _ans: HashSet<i8> = (0..=9).collect();

    for (stat, val) in data {
        let remove_targets: HashSet<i8> = match stat {
            true => &((0..=9).collect::<HashSet<i8>>()) - &(val.iter().cloned().collect()),
            false => val.iter().cloned().collect(),
        };

        for n in remove_targets {
            _ans.remove(&n);
        }
    }

    for n in _ans {
        return n;
    }

    return -1
}

fn main() {
    let data: Vec<(bool, Vec<i8>)> = _read();
    println!("{}", calc(data));
}
0