Submission #818179

# Submission time Handle Problem Language Result Execution time Memory
818179 2023-08-10T03:18:02 Z Sir_Ahmed_Imran Type Printer (IOI08_printer) C++17
30 / 100
159 ms 84476 KB
               ///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define li long int
#define ld long double
#define append push_back
#define add insert
#define nl "\n"
#define ff first
#define ss second
#define pii pair<int,int>
#define pic pair<int,char>
#define all(x) (x).begin(),(x).end()
#define sum(a) accumulate(all(a),0)
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL)
#define terminator main
#define MAXN 100001
class TrieNode {
public:
    bool prt;
    TrieNode* nxt[26];
    TrieNode(){
        for(int i=prt=0;i<26;i++)
            nxt[i]=NULL;
    }
};
class Trie{
public:
    TrieNode* root;
    Trie(){
        root=new TrieNode();
    }
    void insert(string a){
        int m;
        TrieNode* x=root;
        for(int i=0;i<a.size();i++){
            m=a[i]-'a';
            if(!x->nxt[m])
                x->nxt[m]=new TrieNode();
            x=x->nxt[m]; 
        }
        x->prt=1;
    }
    vector<char> dfs(TrieNode* x,vector<char> v){
        vector<pair<int,vector<char>>> a;
        for(int i=0;i<26;i++){
            if(!x->nxt[i]) continue;
            vector<char> u;
            u.append('a'+i);
            if((x->nxt[i])->prt)
                u.append('P');
            u=dfs(x->nxt[i],u);
            u.append('-');
            a.append({u.size(),u});
        }
        sort(all(a));
        for(auto& i:a)
            for(auto& j:i.ss)
                v.append(j);
        return v;
    }
};
void solve(){
    string a;
    int n,m,o,p,q;
    Trie x;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        x.insert(a);
    }
    vector<char> v;
    v=x.dfs(x.root,v);
    m=v.size();
    while(m && v[m-1]=='-')
        m--;
    cout<<m<<nl;
    for(int i=0;i<m;i++)
        cout<<v[i]<<nl;
}
int terminator(){
    L0TA;
    solve();
    return 0;
}

Compilation message

printer.cpp: In member function 'void Trie::insert(std::string)':
printer.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for(int i=0;i<a.size();i++){
      |                     ~^~~~~~~~~
printer.cpp: In function 'void solve()':
printer.cpp:66:13: warning: unused variable 'o' [-Wunused-variable]
   66 |     int n,m,o,p,q;
      |             ^
printer.cpp:66:15: warning: unused variable 'p' [-Wunused-variable]
   66 |     int n,m,o,p,q;
      |               ^
printer.cpp:66:17: warning: unused variable 'q' [-Wunused-variable]
   66 |     int n,m,o,p,q;
      |                 ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1820 KB Output is correct
2 Incorrect 4 ms 2260 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 6072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 14884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 84 ms 37076 KB Output is correct
2 Correct 159 ms 84476 KB Output is correct
3 Incorrect 87 ms 43588 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 29004 KB Output isn't correct
2 Halted 0 ms 0 KB -