Submission #1094392

# Submission time Handle Problem Language Result Execution time Memory
1094392 2024-09-29T14:40:55 Z lenron Type Printer (IOI08_printer) C++17
10 / 100
2 ms 860 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;


int node_num=0,pcount=0;
vector<vector<int>> trie(1000,vector<int>(26,0));
vector<bool> stop(100000,false);
vector<char> ans;

void insert(string word){
    int node=0;
    for(char c:word){
      if(trie[node][c-'a']==0){trie[node][c-'a']=++node_num;pcount++;}
      node=trie[node][c-'a'];
    }
    stop[node]=true;
}

string s="";

void dfs(int u){

     int node=u;
    if(stop[node]==true){ans.push_back('P');}
     for(int i=0;i<26;i++){
        if(trie[node][i]==0){continue;}
        ans.push_back(char('a'+i));
        pcount--;
        int v=trie[node][i];
        dfs(v);
        if(pcount==0){return;}
        ans.push_back('-');
     }

}


void solve(){
   ll n;cin>>n;
   for(int i=0;i<n;i++){
    string s;cin>>s;
    insert(s);
   }
   dfs(0);
   cout<<ans.size()<<endl;
   for(auto x:ans){cout<<x<<endl;}
}


int main(){
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 860 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 860 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 860 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 860 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -