Submission #576893

# Submission time Handle Problem Language Result Execution time Memory
576893 2022-06-13T17:49:18 Z Iwanttobreakfree Type Printer (IOI08_printer) C++
100 / 100
144 ms 45616 KB
#include <iostream>
#include <vector>
#include <map>
using namespace std;
vector<map<char,int>> trie;
vector<bool> fin;
vector<char> ans;
void add(string& s){
    int u=0;
    for(int i=0;i<s.size();i++){
        if(trie[u].find(s[i])==trie[u].end()){
            trie[u][s[i]]=trie.size();
            map<char,int> mp;
            trie.push_back(mp);
            fin.push_back(0);
        }
        u=trie[u][s[i]];
    }
    fin[u]=1;
}
void print(int u,int depth,string& s,bool m){
    if(fin[u])ans.push_back('P');
    //cout<<s<<' ';
    for(auto x:trie[u]){
        if(x.first==s[depth]&&m)continue;
        //cout<<x.first<<' '<<s[depth]<<'\n';
        ans.push_back(x.first);
        print(x.second,depth+1,s,false);
        ans.push_back('-');
    }
    //if(m)cout<<u<<' '<<trie[u][s[depth]]<<'\n';
    if(m&&depth<s.size()){
        ans.push_back(s[depth]);
        print(trie[u][s[depth]],depth+1,s,m);
    }
}
int main(){
    map<char,int> mp;
    trie.push_back(mp);
    fin.push_back(0);
    int n,m=0;
    string s,p;
    cin>>n;
    while(n--){
        cin>>s;
        if(s.size()>m){
            m=s.size();
            p=s;
        }
        add(s);
    }
    print(0,0,p,true);
    cout<<ans.size()<<'\n';
    for(auto x:ans)cout<<x<<'\n';
}

Compilation message

printer.cpp: In function 'void add(std::string&)':
printer.cpp:10:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
printer.cpp: In function 'void print(int, int, std::string&, bool)':
printer.cpp:32:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     if(m&&depth<s.size()){
      |           ~~~~~^~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:46:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |         if(s.size()>m){
      |            ~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 912 KB Output is correct
2 Correct 4 ms 1424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2896 KB Output is correct
2 Correct 21 ms 5868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 7016 KB Output is correct
2 Correct 11 ms 1804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 18908 KB Output is correct
2 Correct 126 ms 38592 KB Output is correct
3 Correct 83 ms 20000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 13476 KB Output is correct
2 Correct 144 ms 45616 KB Output is correct
3 Correct 91 ms 22620 KB Output is correct
4 Correct 117 ms 43232 KB Output is correct