結果
| 問題 |
No.832 麻雀修行中
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 18:52:21 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 2,000 ms |
| コード長 | 1,992 bytes |
| コンパイル時間 | 296 ms |
| コンパイル使用メモリ | 82,216 KB |
| 実行使用メモリ | 54,412 KB |
| 最終ジャッジ日時 | 2025-03-20 18:53:23 |
| 合計ジャッジ時間 | 2,232 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 25 |
ソースコード
def check_case2(counts):
total = sum(counts)
if total != 14:
return False
pair_count = 0
for c in counts:
if c == 0:
continue
elif c == 2:
pair_count += 1
else:
return False
return pair_count == 7
def can_form_triplets(counts):
if all(c == 0 for c in counts):
return True
first = None
for i in range(9):
if counts[i] > 0:
first = i
break
if first is None:
return False
# Try triplet
if counts[first] >= 3:
new_cts = counts.copy()
new_cts[first] -= 3
if can_form_triplets(new_cts):
return True
# Try sequence
if first <= 6:
if counts[first] >= 1 and counts[first + 1] >= 1 and counts[first + 2] >= 1:
new_cts = counts.copy()
new_cts[first] -= 1
new_cts[first + 1] -= 1
new_cts[first + 2] -= 1
if can_form_triplets(new_cts):
return True
return False
def find_agari_tiles(s):
counts = [0] * 9
for c in s:
num = int(c)
counts[num - 1] += 1
possible = []
for t in range(1, 10):
# Check if adding t is possible (original count < 4)
if counts[t-1] >= 4:
continue
new_counts = counts.copy()
new_counts[t-1] += 1
if check_case2(new_counts):
possible.append(t)
continue
# Check case1
found = False
for pair_num in range(1, 10):
if new_counts[pair_num-1] < 2:
continue
temp_counts = new_counts.copy()
temp_counts[pair_num-1] -= 2
if can_form_triplets(temp_counts):
found = True
break
if found:
possible.append(t)
return sorted(possible)
# Read input and process
s = input().strip()
agari_tiles = find_agari_tiles(s)
for tile in agari_tiles:
print(tile)
lam6er