結果

問題 No.832 麻雀修行中
ユーザー phsplsphspls
提出日時 2020-08-12 20:23:00
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,877 bytes
コンパイル時間 1,090 ms
コンパイル使用メモリ 157,824 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 00:49:57
合計ジャッジ時間 1,798 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 0 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn vs7(current: &Vec<usize>) -> bool {
    current.iter().filter(|&v| *v == 2).count() == 7
}

fn is_ok(current: &Vec<usize>, temp: &Vec<usize>, idx: usize, a: usize) -> bool {
    current[idx] >= temp[idx] + a
}

fn normal(current: &Vec<usize>) -> bool {
    let mut result = false;
    current.iter().enumerate().filter(|&pair| *pair.1 >= 2).map(|pair| pair.0).for_each(|i| {
        if result { return; }
        result = true;
        let mut temp: Vec<usize> = vec![0; 10];
        temp[i] = 2;
        for j in 1..10 {
            if current[j] < temp[j] {
                result  = false;
                break;
            }
            let mut diff = current[j] - temp[j];
            if diff == 4 { temp[j] += 3; diff -= 3; }
            match diff {
                3 => { temp[j] += 3; },
                1 | 2 => {
                    if j > 7 || !is_ok(&current, &temp, j+1, diff) || !is_ok(&current, &temp, j+2, diff) {
                        result = false;
                        break;
                    } else {
                        temp[j] += diff;
                        temp[j+1] += diff;
                        temp[j+2] += diff;
                    }
                },
                _ => {}
            }
        }
    });
    result
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let mut current: Vec<usize> = vec![0; 10];
    s.trim().chars()
        .map(|c| c.to_string().parse::<usize>().unwrap())
        .for_each(|i| {
            current[i] += 1;
        });
    let mut result: Vec<String> = vec![];
    for i in 1..10 {
        if current[i] == 4 { continue; }
        current[i] += 1;
        if vs7(&current) || normal(&current) {
            result.push(i.to_string());
        }
        current[i] -= 1;
    }
    result.iter().for_each(|i| {
        println!("{}", i);
    })
}
0