結果

問題 No.832 麻雀修行中
ユーザー betrue12betrue12
提出日時 2019-05-24 22:06:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,591 bytes
コンパイル時間 1,712 ms
コンパイル使用メモリ 173,388 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 12:37:15
合計ジャッジ時間 2,753 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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 <bits/stdc++.h>
using namespace std;

int encode(vector<int>& A){
    int ret = 0;
    for(int a : A){
        ret *= 5;
        ret += a;
    }
    return ret;
}

bitset<2000000> visited, ok;

bool check(vector<int> A){
    int c = encode(A);
    if(c == 0) return true;
    if(visited[c]) return ok[c];
    visited[c] = 1;
    for(int i=0; i<9; i++) if(A[i] >= 3){
        A[i] -= 3;
        if(check(A)){
            ok[c] = 1;
            return true;
        }
        A[i] += 3;
    }
    for(int i=0; i<7; i++){
        bool suff = true;
        for(int k=0; k<3; k++) if(A[i+k] == 0) suff = false;
        if(!suff) continue;
        for(int k=0; k<3; k++) A[i+k]--;
        if(check(A)){
            ok[c] = 1;
            return true;
        }
        for(int k=0; k<3; k++) A[i+k]++;
    }
    return false;
}

bool check2(vector<int> A){
    int t = 0;
    for(int i=0; i<9; i++) if(A[i] == 2) t++;
    return (t == 7);
}

int main(){
    string S;
    cin >> S;
    vector<int> A(9);
    for(char c : S) A[c-'1']++;

    vector<int> ans;
    for(int t=0; t<9; t++){
        if(A[t] == 4) continue;
        A[t]++;
        if(check2(A)){
            ans.push_back(t+1);
            A[t]--;
            continue;
        }
        for(int h=0; h<9; h++){
            if(A[h] < 2) continue;
            A[h] -= 2;
            if(check(A)){
                ans.push_back(t+1);
                A[h] += 2;
                break;
            }
            A[h] += 2;
        }
        A[t]--;
    }

    for(int a : ans) cout << a << endl;
    cerr << "fin";
    return 0;
}
0