結果

問題 No.832 麻雀修行中
ユーザー phspls
提出日時 2020-08-12 20:23:00
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,877 bytes
コンパイル時間 12,350 ms
コンパイル使用メモリ 383,412 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-09 18:34:03
合計ジャッジ時間 13,651 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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