結果

問題 No.832 麻雀修行中
ユーザー trineutrontrineutron
提出日時 2022-04-10 22:37:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,591 bytes
コンパイル時間 2,222 ms
コンパイル使用メモリ 203,164 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 04:09:18
合計ジャッジ時間 3,449 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 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)) {
            hand.at(i) += 3;
            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)) {
            hand.at(i)++; hand.at(i + 1)++; hand.at(i + 2)++;
            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)) {
            hand.at(i) += 2;
            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