結果
| 問題 | 
                            No.2118 遺伝的有限集合の数え上げ
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-11-04 22:25:34 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 683 bytes | 
| コンパイル時間 | 171 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 109,440 KB | 
| 最終ジャッジ日時 | 2024-07-18 20:20:31 | 
| 合計ジャッジ時間 | 6,619 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 10 WA * 27 | 
ソースコード
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))