結果

問題 No.832 麻雀修行中
ユーザー bellangeldindon
提出日時 2019-04-25 15:46:52
言語 Python2
(2.7.18)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,397 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-23 17:35:44
合計ジャッジ時間 2,531 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

def judge(tile):
	cnt = 0
	for i in range(0, 9):
		if tile[i] > 4: return False
	for i in range(0, 9):
		if tile[i] == 2: cnt += 1
	if cnt == 7: return True
	pair = []
	for i in range(0, 9):
		if tile[i] >= 2:
			pair.append(i)
	queue = []
	for i in range(0, len(pair)):
		newtile = []
		for j in range(0, 9):
			if j == pair[i]:
				newtile.append(tile[j]-2)
			else:
				newtile.append(tile[j])
		queue.append(newtile)
	while(queue != []):
		now = queue.pop(0)
		flag = True
		for i in range(0, 9):
			if now[i] != 0:
				flag = False
				break
		if flag: return True

		for i in range(0, 9):
			if now[i] >= 3:
				nexttile = []
				for j in range(0, 9):
					if j == i: nexttile.append(now[j]-3)
					else: nexttile.append(now[j])
				if now != nexttile and nexttile not in queue: queue.append(nexttile)
			if i < 7:
				if now[i] >= 1 and now[i+1] >= 1 and now[i+2] >= 1:
					nexttile = []
					for j in range(0, 9):
						if i <= j and j <= i+2:
							nexttile.append(now[j]-1)
						else: nexttile.append(now[j])
					if now != nexttile and nexttile not in queue: queue.append(nexttile)
	return False

S = raw_input()
tiles = []
for i in range(0, 9):
	tiles.append(0)
for i in range(0, 13):
	n = int(S[i])
	tiles[n-1] += 1
for i in range(0, 9):
	newtiles = []
	for j in range(0, 9):
		if i == j: newtiles.append(tiles[j]+1)
		else: newtiles.append(tiles[j])
	if judge(newtiles): print i+1
0