結果

問題 No.832 麻雀修行中
ユーザー 👑 rin204rin204
提出日時 2022-03-25 04:47:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,243 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 65,152 KB
最終ジャッジ日時 2024-04-21 13:33:31
合計ジャッジ時間 3,150 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
61,824 KB
testcase_01 AC 57 ms
62,208 KB
testcase_02 AC 55 ms
62,208 KB
testcase_03 AC 61 ms
64,384 KB
testcase_04 AC 60 ms
63,744 KB
testcase_05 AC 59 ms
62,848 KB
testcase_06 AC 60 ms
62,336 KB
testcase_07 AC 62 ms
63,616 KB
testcase_08 AC 60 ms
63,360 KB
testcase_09 AC 57 ms
62,464 KB
testcase_10 AC 55 ms
62,848 KB
testcase_11 AC 57 ms
62,720 KB
testcase_12 AC 59 ms
63,488 KB
testcase_13 AC 52 ms
61,056 KB
testcase_14 AC 63 ms
64,896 KB
testcase_15 AC 62 ms
65,152 KB
testcase_16 AC 54 ms
61,312 KB
testcase_17 AC 53 ms
60,800 KB
testcase_18 AC 55 ms
62,080 KB
testcase_19 AC 61 ms
64,128 KB
testcase_20 AC 56 ms
62,080 KB
testcase_21 AC 60 ms
64,256 KB
testcase_22 AC 53 ms
61,056 KB
testcase_23 AC 57 ms
62,720 KB
testcase_24 AC 58 ms
63,488 KB
testcase_25 AC 55 ms
61,440 KB
testcase_26 AC 55 ms
61,056 KB
testcase_27 AC 53 ms
60,928 KB
testcase_28 AC 54 ms
61,568 KB
testcase_29 AC 57 ms
62,592 KB
testcase_30 AC 55 ms
61,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = list(map(int, input()))

def ok(S):
    cnt = [0] * 10
    for s in S:
        cnt[s] += 1
    if all(c in [0, 2] for c in cnt):
        return True
    if any(c >= 5 for c in cnt):
        return False
    
    def dfs(i):
        if i == 5:
            return True
        if i == 0:
            for j in range(1, 10):
                if cnt[j] >= 2:
                    cnt[j] -= 2
                    if dfs(i + 1):
                        return True
                    cnt[j] += 2
        else:
            for j in range(1, 10):
                if cnt[j] >= 3:
                    cnt[j] -= 3
                    if dfs(i + 1):
                        return True
                    cnt[j] += 3
            for j in range(3, 10):
                if cnt[j] >= 1 and cnt[j - 1] >= 1 and cnt[j - 2] >= 1:
                    cnt[j] -= 1
                    cnt[j - 1] -= 1
                    cnt[j - 2] -= 1
                    if dfs(i + 1):
                        return True
                    cnt[j] += 1
                    cnt[j - 1] += 1
                    cnt[j - 2] += 1
            
        return False
    
    return dfs(0)


for i in range(1, 10):
    S.append(i)
    if ok(S[:]):
        print(i)
    S.pop()
    
0