結果

問題 No.832 麻雀修行中
ユーザー YamaKasaYamaKasa
提出日時 2020-01-16 15:55:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,539 bytes
コンパイル時間 1,604 ms
コンパイル使用メモリ 169,720 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 01:12:47
合計ジャッジ時間 3,917 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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