結果
問題 | No.832 麻雀修行中 |
ユーザー |
|
提出日時 | 2022-11-25 15:35:38 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 63 ms / 2,000 ms |
コード長 | 4,571 bytes |
コンパイル時間 | 105 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2024-10-01 23:00:08 |
合計ジャッジ時間 | 3,069 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 25 |
ソースコード
from collections import Counter def remove_sequence(hand: list[int], start: int) -> list[int]: hand_picked = hand.copy() hand_picked.remove(start) hand_picked.remove(start+1) hand_picked.remove(start+2) return hand_picked def remove_head(hand: list[int], head_num: int) -> list[int]: hand_picked = hand.copy() for _ in range(2): hand_picked.remove(head_num) return hand_picked def remove_anko(hand: list[int], anko_num: int) -> list[int]: hand_picked = hand.copy() for _ in range(3): hand_picked.remove(anko_num) return hand_picked def is_agari(hand: list[int], head: int = 1, ments: int = 4) -> bool: hand.sort() assert head >= 0 assert ments >= 0 assert len(hand) == head * 2 + ments * 3 hand_count = Counter(hand) if head == 1 and ments == 0: return len(hand_count) == 1 if head == 0 and ments == 1: if hand[2]-hand[1] == 1 and hand[1]-hand[0] == 1: return True if len(hand_count) == 1: return True return False if len(hand) == 14: if len(hand_count) == 7 and len(set(hand_count.values())) == 1: return True hand.sort() for num in range(1, 10): match hand_count[num]: case 0: continue case 1: if ments == 0: continue try: hand_picked = remove_sequence(hand, num) except ValueError: continue if is_agari(hand_picked, head=head, ments=ments-1): return True case 2: if ments > 0: try: hand_picked = remove_sequence(hand, num) except ValueError: pass else: if is_agari(hand_picked, head=head, ments=ments-1): return True if head > 0: try: hand_picked = remove_head(hand, num) except ValueError: pass else: if is_agari(hand_picked, head=head-1, ments=ments): return True case 3: if ments > 0: try: hand_picked = remove_sequence(hand, num) except ValueError: pass else: if is_agari(hand_picked, head=head, ments=ments-1): return True try: hand_picked = remove_anko(hand, num) except ValueError: pass else: if is_agari(hand_picked, head=head, ments=ments-1): return True if head > 0: try: hand_picked = remove_head(hand, num) except ValueError: pass else: if is_agari(hand_picked, head=head-1, ments=ments): return True case 4: if ments > 0: try: hand_picked = remove_sequence(hand, num) except ValueError: pass else: if is_agari(hand_picked, head=head, ments=ments-1): return True try: hand_picked = remove_anko(hand, num) except ValueError: pass else: if is_agari(hand_picked, head=head, ments=ments-1): return True if head > 0: try: hand_picked = remove_head(hand, num) except ValueError: pass else: if is_agari(hand_picked, head=head-1, ments=ments): return True return False def main(): hand = list(map(int, list(input()))) for num in range(1, 10): if hand.count(num) == 4: continue tumo = hand.copy() tumo.append(num) if is_agari(tumo): print(num) if __name__ == "__main__": main()