結果

問題 No.832 麻雀修行中
ユーザー ThetaTheta
提出日時 2022-11-25 15:35:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
11,136 KB
testcase_01 AC 46 ms
11,136 KB
testcase_02 AC 39 ms
11,264 KB
testcase_03 AC 60 ms
11,136 KB
testcase_04 AC 54 ms
11,136 KB
testcase_05 AC 49 ms
11,264 KB
testcase_06 AC 50 ms
11,136 KB
testcase_07 AC 54 ms
11,136 KB
testcase_08 AC 53 ms
11,264 KB
testcase_09 AC 48 ms
11,136 KB
testcase_10 AC 51 ms
11,136 KB
testcase_11 AC 56 ms
11,136 KB
testcase_12 AC 63 ms
11,136 KB
testcase_13 AC 42 ms
11,264 KB
testcase_14 AC 52 ms
11,136 KB
testcase_15 AC 52 ms
11,136 KB
testcase_16 AC 43 ms
11,136 KB
testcase_17 AC 41 ms
11,264 KB
testcase_18 AC 48 ms
11,136 KB
testcase_19 AC 60 ms
11,136 KB
testcase_20 AC 39 ms
11,264 KB
testcase_21 AC 57 ms
11,136 KB
testcase_22 AC 46 ms
11,264 KB
testcase_23 AC 45 ms
11,136 KB
testcase_24 AC 48 ms
11,136 KB
testcase_25 AC 45 ms
11,264 KB
testcase_26 AC 45 ms
11,136 KB
testcase_27 AC 46 ms
11,264 KB
testcase_28 AC 39 ms
11,136 KB
testcase_29 AC 34 ms
11,136 KB
testcase_30 AC 47 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0