結果

問題 No.24 数当てゲーム
ユーザー yukyuyukyu
提出日時 2021-03-05 01:02:42
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,637 bytes
コンパイル時間 1,244 ms
コンパイル使用メモリ 168,192 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 16:03:46
合計ジャッジ時間 1,908 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

use std::io::*;
use std::str::FromStr;

fn main() {
    let a: String = read();
    let n = a.parse::<i64>().unwrap();
    let mut result: Vec<Vec<i64>> = Vec::new();
    for _ in 0..n {
        let a = (0..5).map(|_| read()).collect::<Vec<String>>();
        let b = vec![
            i64::from_str(&a[0]).unwrap(),
            i64::from_str(&a[1]).unwrap(),
            i64::from_str(&a[2]).unwrap(),
            i64::from_str(&a[3]).unwrap(),
            if &a[4][..] == "YES" { 1 } else { 0 },
        ];
        result.push(b);
    }
    exec(result);
}

fn exec(l: Vec<Vec<i64>>) {
    let mut r: Vec<i64> = (0..10).collect();

    for i in l {
        if let 1 = &i[4] {
            r = include(i, r);
        } else {
            r = exclude(i, r);
        }
    }

    println!("{:?}", r[0]);
}

fn include(t: Vec<i64>, r: Vec<i64>) -> Vec<i64> {
    let mut result: Vec<i64> = Vec::new();
    for i in 0..r.len() {
        for _j in &t[0..4] {
            if &r[i] == _j {
                result.push(r[i]);
            }
        }
    }
    result
}

fn exclude(t: Vec<i64>, r: Vec<i64>) -> Vec<i64> {
    let mut result = r;
    for i in &t[0..4] {
        let arr: Vec<i64> = result.iter().filter(|&x| x != i).cloned().collect();
        result = arr;
    }
    result
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
0