結果

問題 No.832 麻雀修行中
ユーザー YamaKasa
提出日時 2020-01-16 15:55:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,539 bytes
コンパイル時間 1,735 ms
コンパイル使用メモリ 172,288 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-23 20:18:40
合計ジャッジ時間 2,644 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

// a: 手牌 b: 山
int a[9]{};
string S;

void init() {
    fill(a, a + 9, 0);
    for (int i = 0; i < 13; i++) {
        a[S[i] - '1']++;
    }
}


bool check_titoitu() {
    int cnt = 0;
    for (int i = 0; i < 9; i++) {
        if (a[i] == 2) cnt++;
    }
    return cnt == 7 ? true : false;
}

bool flag = false;

void dfs(int n) {
    if (flag) return;
    if (n == 5) {
        flag = true;
        return;
    }
    if (n == 0) {
        for (int i = 0; i < 9; i++) {
            if (a[i] >= 2) {
                a[i] -= 2;
                dfs(n + 1);
                a[i] += 2;
            }
        }
    }
    if (n == 0) return;
    for (int i = 0; i < 9; i++) {
        if (a[i] >= 3) {
            a[i] -= 3;
            dfs(n + 1);
            a[i] += 3;
        }
    }
    for (int i = 0; i + 2 < 9; i++) {
        if (a[i] > 0 && a[i + 1] > 0 && a[i + 2] > 0) {
            a[i]--;
            a[i + 1]--;
            a[i + 2]--;
            dfs(n + 1);
            a[i]++;
            a[i + 1]++;
            a[i + 2]++;
        }
    }
}

int main() {
    cin >> S;
    set<int> s;
    for (int i = 0; i < 9; i++) {
        init();
        if (a[i] != 4) {
            a[i]++;
            if (check_titoitu()) s.insert(i + 1);
            dfs(0);
            if (flag) {
                s.insert(i + 1);
            }
            flag = false;
            a[i]--;
        }
    }
    for (int i : s) {
        cout << i << "\n";
    }
    return 0;
}
0