結果

問題 No.2820 Non-Preferred IUPAC Nomenclature
ユーザー tnakao0123
提出日時 2024-07-29 15:55:50
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 991 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 56,516 KB
最終ジャッジ日時 2025-02-23 19:25:12
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:31:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:36:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |       scanf("%s", s);
      |       ~~~~~^~~~~~~~~

ソースコード

diff #

/* -*- 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