Submission #1103984

# Submission time Handle Problem Language Result Execution time Memory
1103984 2024-10-22T14:11:00 Z LeonidCuk Type Printer (IOI08_printer) C++17
100 / 100
137 ms 98568 KB
#include <bits/stdc++.h>
using namespace std;
struct trie
{
    bool check=false;
    trie* a[26];
    trie()
    {
        for(int i=0;i<26;i++)a[i]=nullptr;
    }
};
string res="";
void peso(trie* m,bool check1,int j)
{
    if(m->check)cout<<"P"<<"\n";
    if(j==res.size()&&check1==false)
    {
        cout<<"-"<<"\n";
        return;
    }
    else if(j==res.size())return;
    int t=res[j]-'a';
    for(int i=0;i<26;i++)
    {
        if(i!=t&&m->a[i]!=nullptr)
        {
            cout<<char('a'+i)<<"\n";
            peso(m->a[i],0,j+1);
        }
    }
    if(m->a[t]!=nullptr)
    {
        cout<<char('a'+t)<<"\n";
        peso(m->a[t],check1,j+1);
    }
    if(!check1)cout<<"-"<<"\n";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,cnt=0,bb=0;
    cin>>n;
    string a;
    trie *root=new trie();
    for(int i=0;i<n;i++)
    {
        cin>>a;
        trie *temp=root;
        if(a.size()>bb)
        {
            bb=a.size();
            res=a;
        }
        for(int j=0;j<a.size();j++)
        {
            int t=a[j]-'a';
            if(temp->a[t]==nullptr)
            {
                temp->a[t]=new trie();
                cnt++;
            }
            temp=temp->a[t];
        }
        temp->check=true;
    }
    cout<<2*cnt-bb+n<<"\n";
    peso(root,1,0);
    return 0;
}

Compilation message

printer.cpp: In function 'void peso(trie*, bool, int)':
printer.cpp:16:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     if(j==res.size()&&check1==false)
      |        ~^~~~~~~~~~~~
printer.cpp:21:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     else if(j==res.size())return;
      |             ~^~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:50:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |         if(a.size()>bb)
      |            ~~~~~~~~^~~
printer.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int j=0;j<a.size();j++)
      |                     ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 440 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 1276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2036 KB Output is correct
2 Correct 3 ms 2128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5968 KB Output is correct
2 Correct 17 ms 12376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 14672 KB Output is correct
2 Correct 7 ms 3408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 35912 KB Output is correct
2 Correct 115 ms 82640 KB Output is correct
3 Correct 61 ms 42736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 28232 KB Output is correct
2 Correct 137 ms 98568 KB Output is correct
3 Correct 74 ms 48456 KB Output is correct
4 Correct 118 ms 93000 KB Output is correct