Submission #511493

# Submission time Handle Problem Language Result Execution time Memory
511493 2022-01-16T00:27:21 Z Yazan_Alattar Type Printer (IOI08_printer) C++14
80 / 100
292 ms 65352 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <utility>
#include <cmath>
#include <numeric>
#include <assert.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 300007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

vector <char> ans;
int n;

struct Trie{
    int to[M][26] = {0}, mx[M] = {0}, sz;
    bool leaf[M] = {0};

    void add(string s){
        int cur = 0;
        mx[0] = max(mx[0], (int)s.size());
        for(int i = 0; i < s.size(); ++i){
            int c = s[i] - 'a';
            if(!to[cur][c]) to[cur][c] = ++sz;
            cur = to[cur][c];
            mx[cur] = max(mx[cur], (int)s.size());
        }
        leaf[cur] = 1;
        return;
    }

    void get(int node){
        vector < pair < pair <int,int>, int > > v;
        for(int i = 0; i < 26; ++i) if(to[node][i]) v.pb({{mx[to[node][i]], i}, to[node][i]});
        sort(all(v));
        if(leaf[node]) ans.pb('P');

        for(auto i : v){
            ans.pb(char('a' + i.F.S));
            get(i.S);
        }
        ans.pb('-');
    }

}T;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++i){
        string s;
        cin >> s;
        T.add(s);
    }
    T.get(0);
    while(ans.back() == '-') ans.pop_back();
    cout << ans.size() << endl;
    for(auto i : ans) cout << i << endl;
    return 0;
}

Compilation message

printer.cpp: In member function 'void Trie::add(std::string)':
printer.cpp:37:26: 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 < s.size(); ++i){
      |                        ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 32204 KB Output is correct
2 Correct 12 ms 32304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 32204 KB Output is correct
2 Correct 13 ms 32204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 32204 KB Output is correct
2 Correct 12 ms 32232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 32244 KB Output is correct
2 Correct 14 ms 32236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 32204 KB Output is correct
2 Correct 13 ms 32252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 32368 KB Output is correct
2 Correct 19 ms 32332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 32428 KB Output is correct
2 Correct 24 ms 32748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 32812 KB Output is correct
2 Correct 19 ms 32460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 33348 KB Output is correct
2 Runtime error 292 ms 65332 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 33228 KB Output is correct
2 Runtime error 278 ms 65352 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -