結果

問題 No.832 麻雀修行中
ユーザー leaf_1415
提出日時 2019-05-24 23:21:15
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,009 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 57,000 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-17 12:35:41
合計ジャッジ時間 1,420 ms
ジャッジサーバーID
(参考情報)
judge4 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>

using namespace std;

string s;
int cnt[10];

bool solve()
{
	int sum = 0;
	for(int i = 1; i <= 9; i++) sum += cnt[i];
	if(sum == 0) return true;
	
	bool ret = false;
	for(int i = 1; i <= 9; i++){
		if(cnt[i] == 0) continue;
		if(cnt[i] >= 3){
			cnt[i] -= 3;
			ret |= solve();
			cnt[i] += 3;
		}
		if(i <= 7 && cnt[i] && cnt[i+1] && cnt[i+2]){
			cnt[i]--, cnt[i+1]--, cnt[i+2]--;
			ret |= solve();
			cnt[i]++, cnt[i+1]++, cnt[i+2]++;
		}
	}
	return ret;
}

int main(void)
{
	cin >> s;
	for(int i = 0; i < s.size(); i++) cnt[s[i]-'0']++;
	
	for(int i = 1; i <= 9; i++){
		if(cnt[i] == 4) continue;
		cnt[i]++;
		
		bool flag = true;
		for(int j = 1; j <= 9; j++){
			if(cnt[j] != 0 && cnt[j] != 2) flag = false;
		}
		if(flag){
			cout << i << endl;
			continue;
		}
		
		bool ans = false;
		for(int j = 1; j <= 9; j++){
			if(cnt[j] >= 2){
				cnt[j] -= 2;
				ans |= solve();
				cnt[j] += 2;
			}
		}
		cnt[i]--;
		
		if(ans) cout << i << endl;
	}
	
	return 0;
}
0