結果

問題 No.2820 Non-Preferred IUPAC Nomenclature
ユーザー hiromi_ayase
提出日時 2024-07-26 23:07:35
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,191 bytes
コンパイル時間 5,704 ms
コンパイル使用メモリ 312,476 KB
実行使用メモリ 29,548 KB
最終ジャッジ日時 2024-07-26 23:07:45
合計ジャッジ時間 9,661 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other TLE * 1 -- * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define FAST_IO                \
  ios::sync_with_stdio(false); \
  cin.tie(0);
const i64 INF = 1001001001001001001;
using Modint = atcoder::static_modint<998244353>;

string dfs(int v, vector<vector<int>> &G, vector<bool> &visited) {
  visited[v] = true;
  string ret = "";
  for (int u : G[v]) {
    if (visited[u]) continue;

    string res = dfs(u, G, visited);
    ret += "(" + res + ")";
  }
  ret += "methyl";
  return ret;
}

int main() {
  FAST_IO
  auto ans = 0LL;

  int N;
  cin >> N;

  vector<vector<int>> G(N);
  for (int i = 0; i < N; i ++) {
    string C1, C2, C3, C4;
    cin >> C1 >> C2 >> C3 >> C4;
    if (C1 != "H") {
      G[i].push_back(stoi(C1) - 1);
    }
    if (C2 != "H") {
      G[i].push_back(stoi(C2) - 1);
    }
    if (C3 != "H") {
      G[i].push_back(stoi(C3) - 1);
    }
    if (C4 != "H") {
      G[i].push_back(stoi(C4) - 1);
    }
  }

  auto visited = vector<bool>(N, false);
  auto ret = dfs(0, G, visited);

  ret = ret.substr(0, ret.size() - 2) + "ane";
  cout << ret << endl;
}
0