Submission #931379

# Submission time Handle Problem Language Result Execution time Memory
931379 2024-02-21T16:53:21 Z rahidilbayramli Type Printer (IOI08_printer) C++17
30 / 100
55 ms 56220 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define pb push_back
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll sz = 1e5+5;
ll triee[sz][26], value[sz], subtree[sz], next_node = 1;
map<ll, char>mp;
vector<char>res;
void add(string& s, ll id)
{
    ll node = 0;
    for(ll idx = 0; idx < s.size(); idx++)
    {
        ll ch = s[idx] - 'a';
        if(!triee[node][ch]){
            triee[node][ch] = next_node;
            mp[next_node] = s[idx];
            next_node++;
        }
        node = triee[node][ch];
    }
    value[node] = 1;
}
void dfs1(ll node = 0)
{
    subtree[node] = 1;
    for(ll i = 0; i < 26; i++)
    {
        if(triee[node][i]){
            dfs1(triee[node][i]);
            subtree[node] += subtree[triee[node][i]];
        }
    }
}
void dfs(ll node = 0)
{
    if(node)
        res.pb(mp[node]);
    if(value[node])
        res.pb('P');
    priority_queue<pll>vv;
    for(ll i = 0; i < 26; i++)
    {
        if(triee[node][i])
            vv.push({-subtree[triee[node][i]], triee[node][i]});
    }
    while(!vv.empty()){
        dfs(vv.top().s);
        vv.pop();
    }
    res.pb('-');
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tests = 1;
    //cin >> tests;
    while(tests--)
    {
        ll n, i;
        cin >> n;
        for(i = 1; i <= n; i++)
        {
            string s;
            cin >> s;
            add(s, i);
        }
        dfs1();
        dfs();
        while(res.back() == '-')
            res.pop_back();
        cout << res.size() << "\n";
        for(auto u : res)
            cout << u << "\n";
    }
}

Compilation message

printer.cpp: In function 'void add(std::string&, long long int)':
printer.cpp:24:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(ll idx = 0; idx < s.size(); idx++)
      |                     ~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2396 KB Output is correct
2 Incorrect 4 ms 2908 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 7516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 18896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 55 ms 56220 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 47 ms 56144 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -