Submission #872795

# Submission time Handle Problem Language Result Execution time Memory
872795 2023-11-13T20:08:21 Z assem_albitar Type Printer (IOI08_printer) C++17
100 / 100
122 ms 108028 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define mxe(v)   *max_element(v.begin(), v.end())
#define all(v)   v.begin(), v.end()
#define allr(v) v.rbegin(),v.rend()
#define F first
#define S second
#define pi pair<ll,ll>
#define assem ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
using namespace std;
const int N=400200;
const double PI=3.1415926535897932384626433;
const double eps = 1e-9;
string getString()
{
    char c[(int)21];
    //scanf(" %c",&a[i]);
    scanf("%s", c);
    return c;
    //string x = getString();
}
///printf("%d\n",);
///scanf("%d",&);
///cout.precision(10);
///puts("")string
vector<char> ans;
int n;
vector<string> v;
struct trie
{
    int cnt,c,mx;
    trie* child[26];
    trie()
    {
        cnt=c=mx=0;
        memset(child,0,sizeof child);
    }
    void add(int i,int j)
    {
        if(j==v[i].size())
        {
            c++;
            cnt=max(cnt,j);
            return;
        }
        if(child[v[i][j]-'a']==0)child[v[i][j]-'a']=new trie();
        child[v[i][j]-'a']->add(i,j+1);
        cnt=max(cnt,child[v[i][j]-'a']->cnt);
    }
    void get()
    {
        while(c>0)
        {
            c--;
            ans.push_back('P');
        }
        vector<pair<int,char>> a;
        for(char i='a'; i<='z'; i++)
        {
            if(child[i-'a']!=0)
            {
                a.push_back({child[i-'a']->cnt,i});
            }
        }
        sort(all(a));
        for(int i=0; i<a.size(); i++)
        {
            ans.push_back(a[i].S);
            child[a[i].S-'a']->get();
            ans.push_back('-');
        }
        return;
    }
};
int main()
{
    scanf("%d",&n);
    trie* root=new trie();
    for(int i=0; i<n; i++)
    {
        string q;
        q=getString();
        v.push_back(q);
        root->add(i,0);
    }
    root->get();
    while(ans.back()=='-')ans.pop_back();
    printf("%d\n",(int)ans.size());
    for(int i=0; i<ans.size(); i++)
    {
        printf("%c\n",ans[i]);
    }
}

Compilation message

printer.cpp: In member function 'void trie::add(int, int)':
printer.cpp:44:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         if(j==v[i].size())
      |            ~^~~~~~~~~~~~~
printer.cpp: In member function 'void trie::get()':
printer.cpp:70:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for(int i=0; i<a.size(); i++)
      |                      ~^~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:93:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |     for(int i=0; i<ans.size(); i++)
      |                  ~^~~~~~~~~~~
printer.cpp: In function 'std::string getString()':
printer.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%s", c);
      |     ~~~~~^~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:81:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
# 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 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1884 KB Output is correct
2 Correct 3 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6492 KB Output is correct
2 Correct 15 ms 13784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 16336 KB Output is correct
2 Correct 7 ms 4056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 40388 KB Output is correct
2 Correct 105 ms 90956 KB Output is correct
3 Correct 60 ms 47816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 31940 KB Output is correct
2 Correct 122 ms 108028 KB Output is correct
3 Correct 63 ms 54476 KB Output is correct
4 Correct 108 ms 101956 KB Output is correct