結果

問題 No.2820 Non-Preferred IUPAC Nomenclature
ユーザー れもん丸
提出日時 2024-07-26 22:28:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,350 bytes
コンパイル時間 2,500 ms
コンパイル使用メモリ 179,076 KB
実行使用メモリ 40,396 KB
最終ジャッジ日時 2024-07-26 22:28:59
合計ジャッジ時間 6,403 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 RE * 1
other AC * 2 WA * 8 RE * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i = 0; i < n; ++i)
using ll = long long;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 998244353;
constexpr bool debug = false;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
//---------------------------------//

string GetName(const vector<set<int>>& Alkane, int root, vector<bool>& visited){
    visited[root] = true;
    string name = "";

    for (int child : Alkane[root]){
        if (visited[child]) continue;

        string ChildName = GetName(Alkane, child, visited);
        for (int cnt = 0; cnt < 3; cnt++) ChildName.pop_back();
        name += "(" + ChildName + "yl)";
    }

    name += "methane";

    return name;
}

int main(){
    int N;
    cin >> N;

    vector<set<int>> Alkane(N, set<int>());
    for (int i = 0; i < N; ++i){
        for (int j = 0; j < 4; ++j){
            char c;
            cin >> c;
            if (c != 'H'){
                Alkane[i].insert(c-'1');
            }
        }
    }

    vector<bool> visited(N, false);

    cout << GetName(Alkane, 0, visited) << endl;

    return 0;
}
0