Submission #1117284

# Submission time Handle Problem Language Result Execution time Memory
1117284 2024-11-23T08:16:27 Z Newtonabc Type Printer (IOI08_printer) C++14
0 / 100
266 ms 262144 KB
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
int trie[N][30];
bool word[N];
int cnt,sz[N],path[N];
stack<int> st;
vector<int> adj[N];
char type[N];
vector<char> pt;
void insert(string s){
    int u=0;
    for(int i=0;i<s.size();i++){
        if(trie[u][s[i]-'a']==0){
            trie[u][s[i]-'a']=++cnt;
            type[cnt]=s[i];
            adj[cnt].push_back(u);
            adj[u].push_back(cnt);
        }
        u=trie[u][s[i]-'a'];
    }
    word[u]=true;
}
void findsz(int u,int p){
    sz[u]=0;
    for(int i=0;i<adj[u].size();i++){
        int v=adj[u][i];
        if(v==p) continue;
        findsz(v,u);
        if(sz[v]+1>sz[u]){
            sz[u]=sz[v]+1;
            path[u]=v;
        }
    }
}
void dfs(int u,int p){
    while(!st.empty() && st.top()!=p) pt.push_back('-'),st.pop();
    if(u) st.push(u);
    if(u) pt.push_back(type[u]);
    if(word[u] && u) pt.push_back('P');
    for(int i=0;i<adj[u].size();i++){
        int v=adj[u][i];
        if(v==p || v==path[u]) continue;
        dfs(v,u);
    }
    dfs(path[u],u);

}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string inp;
        cin>>inp;
        insert(inp);
    }
    dfs(0,0);
    cout<<pt.size() <<"\n";
    for(int i=0;i<pt.size();i++){
        cout<<pt[i] <<"\n";
    }
}

Compilation message

printer.cpp: In function 'void insert(std::string)':
printer.cpp:13:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
printer.cpp: In function 'void findsz(int, int)':
printer.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i=0;i<adj[u].size();i++){
      |                 ~^~~~~~~~~~~~~~
printer.cpp: In function 'void dfs(int, int)':
printer.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i=0;i<adj[u].size();i++){
      |                 ~^~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i=0;i<pt.size();i++){
      |                 ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 224 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 238 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 240 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 234 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 233 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 246 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 245 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 248 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 260 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 266 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -