結果

問題 No.2118 遺伝的有限集合の数え上げ
ユーザー lloyz
提出日時 2022-11-04 21:54:22
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 399 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-07-18 19:39:19
合計ジャッジ時間 2,276 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)

memo = {0: '{}'}
def rec(x):
    if x in memo:
        return memo[x]
    res = '{'
    digit = 0
    xc = x
    while xc != 0:
        xc, r = divmod(xc, 2)
        if r == 1:
            res += rec(digit) + ','
        digit += 1
    if res[-1] == ',':
        res = res[:-1]
    res += '}'
    memo[x] = res
    return res

n = int(input())
print(rec(n))
0