結果

問題 No.832 麻雀修行中
ユーザー trineutrontrineutron
提出日時 2019-06-15 02:00:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,397 bytes
コンパイル時間 1,780 ms
コンパイル使用メモリ 172,956 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 16:53:58
合計ジャッジ時間 2,806 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

bool mentsu(vector<int> hand, int remaining) {
    if (remaining == 0) return true;
    for (int i = 0; i < 9; i++) {
        if (hand.at(i) < 3) continue;
        hand.at(i) -= 3;
        if (mentsu(hand, remaining - 1)) return true;
        hand.at(i) += 3;
    }
    for (int i = 0; i < 7; i++) {
        if (hand.at(i) == 0 || hand.at(i + 1) == 0 || hand.at(i + 2) == 0) continue;
        hand.at(i)--; hand.at(i + 1)--; hand.at(i + 2)--;
        if (mentsu(hand, remaining - 1)) return true;
        hand.at(i)++; hand.at(i + 1)++; hand.at(i + 2)++;
    }
    return false;
}

bool isagari(vector<int> hand) {
    bool seven_pairs = true;
    for (int i = 0; i < 9; i++) {
        if (hand.at(i) != 0 && hand.at(i) != 2) {
            seven_pairs = false;
            break;
        }
    }
    if (seven_pairs) return true;
    for (int i = 0; i < 9; i++) {
        if (hand.at(i) < 2) continue;
        hand.at(i) -= 2;
        if (mentsu(hand, 4)) return true;
        hand.at(i) += 2;
    }
    return false;
}

int main()
{
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    vector<int> hand(9);
    for (int i = 0; i < 13; i++) hand.at(s.at(i) - '1')++;
    for (int i = 0; i < 9; i++) {
        if (hand.at(i) == 4) continue;
        hand.at(i)++;
        if (isagari(hand)) cout << i + 1 << endl;
        hand.at(i)--;
    }
}
0