結果

問題 No.2820 Non-Preferred IUPAC Nomenclature
ユーザー Nzt3Nzt3
提出日時 2024-07-26 22:07:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 2,797 ms
コンパイル使用メモリ 202,856 KB
実行使用メモリ 13,624 KB
最終ジャッジ日時 2024-07-26 22:07:14
合計ジャッジ時間 8,473 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 97 ms
13,624 KB
testcase_05 AC 46 ms
9,472 KB
testcase_06 AC 80 ms
12,872 KB
testcase_07 AC 11 ms
5,376 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 9 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int MOD=998244353;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,l,r) for(int i=(l);i<(int)(r);i++)

void dfs(const vector<array<int,4>>& A,int v,int p,string& ret,int root=0){
  if(!root){
    ret+='(';
  }
  rep(i,4){
    if(A[v][i]!=p&&A[v][i]!=-1){
      dfs(A,A[v][i],v,ret);
    }
  }
  if(root){
    ret+="methane";
  }else{
    ret+="methyl)";
  }
  return;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin>>N;
  vector A(N,array<int,4>());
  rep(i,N){
    rep(j,4){
      string S;
      cin>>S;
      if(S=="H"){
        A[i][j]=-1;
      }else{
        A[i][j]=stoi(S)-1;
      }
    }
  }
  string ans="";
  dfs(A,0,-1,ans,1);
  cout<<ans<<'\n';
}
0