結果

問題 No.832 麻雀修行中
ユーザー leaf_1415leaf_1415
提出日時 2019-05-24 23:21:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,009 bytes
コンパイル時間 585 ms
コンパイル使用メモリ 57,136 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 14:50:13
合計ジャッジ時間 1,516 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 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 1 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 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 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 <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