Submission #604723

# Submission time Handle Problem Language Result Execution time Memory
604723 2022-07-25T09:13:24 Z neki Type Printer (IOI08_printer) C++14
100 / 100
170 ms 57940 KB
#include <bits/stdc++.h>
#define ll long long
#define vc vector
using namespace std;

const ll mn =500100;
ll cnt=0;
map<char, ll> tr[mn];
ll konci[mn];

void add(string s){
    ll cur=0;
    for(auto v: s){
        if(tr[cur].find(v)==tr[cur].end()) tr[cur][v]=++cnt;
        cur=tr[cur][v];
    }
    assert(cnt<mn);
    assert(cur<mn);
    ++konci[cur];
}

vc<char> ans;
void dfs(ll u, string& izogni, ll ind){
    for(ll i=0;i<konci[u];++i) ans.push_back('P');
    
    for(auto v: tr[u]){
        if(ind<izogni.size() and v.first==izogni[ind]) continue;
        
        ans.push_back(v.first);
        dfs(v.second, izogni, ind+1);
        ans.push_back('-');
    }
    if(ind<izogni.size() and tr[u].find(izogni[ind])!=tr[u].end()){
        ans.push_back(izogni[ind]);
        dfs(tr[u][izogni[ind]], izogni, ind+1);
        ans.push_back('-');
    }
}

int main() {
    ll n;cin >> n;
    string l="";
    for(ll i=0;i<n;++i){
        string s;cin >> s;
        if(l.size()<s.size()) l=s;
        add(s);
    }
    dfs(0, l, 0);
    
    while(ans.back()=='-') ans.pop_back();
    
    cout << ans.size()<<'\n';
    for(auto v: ans) cout << v << '\n';
}

Compilation message

printer.cpp: In function 'void dfs(long long int, std::string&, long long int)':
printer.cpp:27:15: 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]
   27 |         if(ind<izogni.size() and v.first==izogni[ind]) continue;
      |            ~~~^~~~~~~~~~~~~~
printer.cpp:33:11: 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]
   33 |     if(ind<izogni.size() and tr[u].find(izogni[ind])!=tr[u].end()){
      |        ~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 12 ms 23784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23764 KB Output is correct
2 Correct 14 ms 23748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23800 KB Output is correct
2 Correct 14 ms 24020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 24320 KB Output is correct
2 Correct 15 ms 24404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 25728 KB Output is correct
2 Correct 28 ms 28032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 28760 KB Output is correct
2 Correct 23 ms 24972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 36424 KB Output is correct
2 Correct 141 ms 52492 KB Output is correct
3 Correct 84 ms 38676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 33608 KB Output is correct
2 Correct 170 ms 57940 KB Output is correct
3 Correct 96 ms 40744 KB Output is correct
4 Correct 125 ms 55956 KB Output is correct