結果
問題 | No.2820 Non-Preferred IUPAC Nomenclature |
ユーザー |
|
提出日時 | 2024-04-06 17:20:55 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,189 ms / 2,000 ms |
コード長 | 819 bytes |
コンパイル時間 | 2,305 ms |
コンパイル使用メモリ | 77,312 KB |
実行使用メモリ | 81,892 KB |
最終ジャッジ日時 | 2024-07-26 16:27:50 |
合計ジャッジ時間 | 15,094 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 22 |
ソースコード
import java.util.Scanner; class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[][] path = new int[N][]; for(int i=0;i<N;i++){ int[] temp = new int[4]; for(int j=0;j<4;j++){ String C = sc.next(); if(C.equals("H")) temp[j] = -1; else temp[j] = Integer.parseInt(C)-1; } path[i] = temp; } StringBuilder ans = new StringBuilder(); dfs(0,path,ans); System.out.println(ans.toString()); } private static void dfs(int now,int[][] path,StringBuilder ans){ for(int next:path[now]){ if(next!=-1){ ans.append("("); for(int i=0;i<4;i++) if(path[next][i]==now) path[next][i] = -1; dfs(next,path,ans); ans.replace(ans.length()-3,ans.length(),"yl)"); } } ans.append("methane"); } }