結果

問題 No.2820 Non-Preferred IUPAC Nomenclature
ユーザー titia
提出日時 2024-07-27 01:27:39
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 570 bytes
コンパイル時間 561 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 61,184 KB
最終ジャッジ日時 2024-07-27 01:27:43
合計ジャッジ時間 3,948 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15 RE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

sys.setrecursionlimit(200020)

N=int(input())
C=[input().split() for i in range(N)]

USE=[0]*N

from functools import lru_cache
@lru_cache(maxsize=None)
def dfs(x):
    USE[x]=1
    ANS=[]
    for i in range(4):
        if C[x][i]=="H":
            continue
        k=int(C[x][i])-1
        
        if USE[k]==1:
            continue

        ANS.append("(")
        ANS.append("".join(dfs(k)))
        ANS.append(")")

    ANS.append("methyl")

    #print(ANS)

    return ANS

ANS=dfs(0)

ANS[-1]="methane"

print("".join(ANS))
0