結果

問題 No.832 麻雀修行中
ユーザー tomarint2tomarint2
提出日時 2019-05-24 23:01:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,061 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 85,492 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 14:10:30
合計ジャッジ時間 1,964 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <unordered_map>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0
template <class T>
void dumplist(T list)
{
    for (auto item : list) {
        cout << item << " ";
    }
    cout << endl;
}

bool check1(vll& hand)
{
    ll count = 0;
    ll max1 = 0;
    for2(i,1,10) {
        count += hand[i];
        max1 = max(max1, hand[i]);
    }
    if (count == 2) {
        if (max1 == 2) {
            return true;
        } else {
            return false;
        }
    }

    bool ret;
    for2(i,1,10) {
        if (hand[i] >= 3) {
            hand[i] -= 3;
            ret = check1(hand);
            hand[i] += 3;
            if (ret) {
                return true;
            }
        }
    }
    for2(i,1,8) {
        if (hand[i] >= 1 && hand[i+1] >= 1 && hand[i+2] >= 1) {
            hand[i] -= 1;
            hand[i+1] -= 1;
            hand[i+2] -= 1;
            ret = check1(hand);
            hand[i] += 1;
            hand[i+1] += 1;
            hand[i+2] += 1;
            if (ret) {
                return true;
            }
        }
    }
    return false;
}

bool check2(vll& hand)
{
    ll ok = 0;
    for2(i,1,10) {
        if (hand[i] == 2) {
            ++ok;
        }
    }
    if (ok == 7) {
        return true;
    }
    return false;
}

void solve()
{
    string S;
    vll hand(10,0);
    cin >> S;
    for (char c : S) {
        hand[c - '0'] += 1;
    }
    for2(i,1,10) {
        //dumplist(hand);
        if (hand[i] <= 3) {
            hand[i] += 1;
            if (check1(hand) || check2(hand)) {
                cout << i << endl;
            }
            hand[i] -= 1;
        }
    }
}

int main()
{
    do {
        solve();
    } while (DEBUG);
}
0