結果
問題 | No.2820 Non-Preferred IUPAC Nomenclature |
ユーザー |
![]() |
提出日時 | 2024-07-27 05:31:33 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,364 bytes |
コンパイル時間 | 555 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 681,328 KB |
最終ジャッジ日時 | 2024-07-27 05:31:40 |
合計ジャッジ時間 | 6,070 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | MLE * 1 -- * 21 |
ソースコード
import sysinput = sys.stdin.readlinefrom operator import itemgetterN=int(input())C=[input().split() for i in range(N)]E=[[] for i in range(N)]for i in range(N):for j in range(4):if C[i][j]=="H":continuex=int(C[i][j])-1E[i].append(x)# 木のHL分解+LCAROOT=0QUE=[ROOT]Parent=[-1]*NParent[ROOT]=N # ROOTの親を定めておく.Child=[[] for i in range(N)]TOP_SORT=[] # トポロジカルソートwhile QUE: # トポロジカルソートと同時に親を見つけるx=QUE.pop()TOP_SORT.append(x)for to in E[x]:if Parent[to]==-1:Parent[to]=xChild[x].append(to)QUE.append(to)Children=[1]*Nfor x in TOP_SORT[::-1]: #(自分を含む)子ノードの数を調べるif x==ROOT:breakChildren[Parent[x]]+=Children[x]DP=[[] for i in range(N)]for x in TOP_SORT[::-1]:#print(DP)if Child[x]==[]:DP[x]=["(methyl)"]else:LIST=[]for c in Child[x]:LIST.append((Children[c],c))LIST.sort(key=itemgetter(0),reverse=True)NOW=["("]for _,c in LIST:NOW+=DP[c]NOW.append("methyl")NOW.append(")")DP[x]=NOWANS=DP[0][1:]ANS.pop()ANS[-1]="methane"print("".join(ANS))