結果

問題 No.2820 Non-Preferred IUPAC Nomenclature
コンテスト
ユーザー tnakao0123
提出日時 2024-07-29 15:55:50
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 991 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 231 ms
コンパイル使用メモリ 70,260 KB
実行使用メモリ 16,088 KB
最終ジャッジ日時 2026-07-05 08:54:36
合計ジャッジ時間 4,108 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 2820.cc:  No.2820 Non-Preferred IUPAC Nomenclature - yukicoder
 */

#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

using vi = vector<int>;

/* global variables */

vi nbrs[MAX_N];
int ps[MAX_N], cis[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  
  for (int u = 0; u < n; u++)
    for (int j = 0; j < 4; j++) {
      char s[8];
      scanf("%s", s);
      if (s[0] != 'H') {
	int v = atoi(s) - 1;
	nbrs[u].push_back(v);
      }
    }

  ps[0] = -1;
  for (int u = 0; u >= 0;) {
    auto &nbru = nbrs[u];
    int up = ps[u];

    if (cis[u] < nbru.size()) {
      int v = nbru[cis[u]++];
      if (v != up) {
	ps[v] = u;
	putchar('(');
	u = v;
      }
    }
    else {
      //printf("%d:meth", u);
      printf("meth");
      if (up >= 0) printf("yl)");
      else printf("ane");
      u = up;
    }
  }
  putchar('\n');

  return 0;
}
0