結果

問題 No.832 麻雀修行中
ユーザー betrue12
提出日時 2019-05-24 22:06:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,591 bytes
コンパイル時間 1,767 ms
コンパイル使用メモリ 174,488 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-17 10:43:00
合計ジャッジ時間 3,050 ms
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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