Submission #1365225

#TimeUsernameProblemLanguageResultExecution timeMemory
1365225abmr59Type Printer (IOI08_printer)C++20
Compilation error
0 ms0 KiB
#include "bits/stdc++.h"
#define mod 1000000007
#define inf 4000000000000000000
using namespace std;
#define int long long
 
struct node{
    node* adj[26];
    int dep, maxd, num;
    node(){
        for(int i=0; i<26; i++) adj[i]=0;
        dep=0; maxd=0;
        num=0;
    }
};
string ans;
node* root = new node;
void Insert(string s){
    node* cur = root;
    for(char c : s) if(!cur -> adj[c-'a']) cur -> adj[c-'a'] = new node;
    cur -> num++;
}

void dfs1(auto cur){
    for(int i=0; i<26; i++){
        if(cur -> adj[i]){
            cur -> adj[i] -> dep=cur -> dep +1;
            dfs1(cur -> adj[i]);
            cur -> maxd=max(cur -> adj[i] -> maxd, cur -> maxd);
        }
    }
}
void dfs2(auto cur){
    while(cur -> num--) ans+="P";
    int m=-1;
    for(int i=0; i<26; i++){
        if(cur -> adj[i]){
            if(m==-1 or cur -> adj[i] -> maxd > cur -> adj[m] -> maxd) m=i;
        }
    }
    for(int i=0; i<26; i++) if(cur -> adj[i]){
        if(cur -> adj[i] and i!=m){
            ans+=i+'a';
            dfs2(i);
            ans+='-';
        }
    }
    ans+=m+'a';
    dfs2(m);
    ans+='-';
}

signed main(){
    int n; cin>>n;
    for(int i=0; i<n; i++){
        string s; cin>>s;
        Insert(s);
    }
    dfs1(root); dfs2(root);
    while(ans.back()=='-') ans.pop_back();
    cout<<ans.size()<<'\n';
    for(auto c : ans) cout<<c<<'\n';
}

Compilation message (stderr)

printer.cpp: In instantiation of 'void dfs2(auto:55) [with auto:55 = long long int]':
printer.cpp:44:17:   required from 'void dfs2(auto:55) [with auto:55 = node*]'
printer.cpp:59:21:   required from here
printer.cpp:34:11: error: base operand of '->' is not a pointer
   34 |     while(cur -> num--) ans+="P";
      |           ^~~
printer.cpp:37:12: error: base operand of '->' is not a pointer
   37 |         if(cur -> adj[i]){
      |            ^~~
printer.cpp:38:25: error: base operand of '->' is not a pointer
   38 |             if(m==-1 or cur -> adj[i] -> maxd > cur -> adj[m] -> maxd) m=i;
      |                         ^~~
printer.cpp:38:49: error: base operand of '->' is not a pointer
   38 |             if(m==-1 or cur -> adj[i] -> maxd > cur -> adj[m] -> maxd) m=i;
      |                                                 ^~~
printer.cpp:41:32: error: base operand of '->' is not a pointer
   41 |     for(int i=0; i<26; i++) if(cur -> adj[i]){
      |                                ^~~
printer.cpp:42:12: error: base operand of '->' is not a pointer
   42 |         if(cur -> adj[i] and i!=m){
      |            ^~~