結果

問題 No.832 麻雀修行中
ユーザー trineutrontrineutron
提出日時 2022-04-10 22:36:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,399 bytes
コンパイル時間 2,216 ms
コンパイル使用メモリ 203,540 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-21 04:07:43
合計ジャッジ時間 4,122 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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