結果

問題 No.2118 遺伝的有限集合の数え上げ
コンテスト
ユーザー roaris
提出日時 2022-11-04 22:25:34
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 683 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 153 ms
コンパイル使用メモリ 85,212 KB
実行使用メモリ 165,448 KB
最終ジャッジ日時 2026-04-02 12:25:02
合計ジャッジ時間 3,979 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import *

def f(x):
    if memo[x]!=-1:
        return memo[x]
    
    if x==0:
        return '{}'
    
    i = 0
    
    if x==N:
        s = set()
        
        while x:
            if x%2:
                s.add(f(i))
            x //= 2
            i += 1
        
        res = '{'+','.join(list(s))+'}'
    else:
        res = ['{']
        
        while x:
            if x%2:
                res.append(f(i))
                res.append(',')
            x //= 2
            i += 1
    
        res.pop()
        res.append('}')
        res = ''.join(res)
    
    memo[x] = res
    return res

N = int(input())
memo = defaultdict(lambda: -1)
print(f(N))
0