Submission #721321

# Submission time Handle Problem Language Result Execution time Memory
721321 2023-04-10T16:45:55 Z thimote75 Type Printer (IOI08_printer) C++14
90 / 100
1000 ms 57896 KB
#include <bits/stdc++.h>

using namespace std;

vector<char> chr_buffer;

struct Trie {
    map<char, Trie*> m;
    int count  = 0;
    int mxSize = 0;

    void append (string &buffer, int offset) {
        if (offset == buffer.size()) { count ++; return ; }

        mxSize = max(mxSize, (int) buffer.size());

        if (m.find(buffer[offset]) == m.end())
            m.insert({ buffer[offset], new Trie() });
        
        Trie* tr = (*m.find(buffer[offset])).second;
        tr->append(buffer, offset + 1);
    }

    void show () {
        for (int i = 0; i < count; i ++)
            chr_buffer.push_back('P');

        bool found = false;
        for (auto u : m) {
            if (u.second->mxSize == mxSize && !found) {
                found = true;
                continue ;
            }
            chr_buffer.push_back(u.first);
            u.second->show();
            chr_buffer.push_back('-');
        }

        for (auto u : m) {
            if (u.second->mxSize != mxSize) continue ;

            chr_buffer.push_back(u.first);
            u.second->show();
            chr_buffer.push_back('-');
            break;
        }
    }
};

Trie res;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N;
    cin >> N;

    string b;
    for (int i = 0; i < N; i ++) {
        cin >> b;
        res.append(b, 0);
    }

    res.show();

    while (chr_buffer[chr_buffer.size() - 1] == '-')
        chr_buffer.pop_back();
    
    cout << chr_buffer.size() << endl;
    for (char c : chr_buffer)
        cout << c << endl;
}

Compilation message

printer.cpp: In member function 'void Trie::append(std::string&, int)':
printer.cpp:14:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         if (offset == buffer.size()) { count ++; return ; }
      |             ~~~~~~~^~~~~~~~~~~~~~~~
# 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 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 11 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1200 KB Output is correct
2 Correct 32 ms 1456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 3580 KB Output is correct
2 Correct 143 ms 7488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 8676 KB Output is correct
2 Correct 50 ms 2068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 454 ms 21504 KB Output is correct
2 Correct 925 ms 48764 KB Output is correct
3 Correct 501 ms 25540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 351 ms 16736 KB Output is correct
2 Execution timed out 1082 ms 57896 KB Time limit exceeded
3 Halted 0 ms 0 KB -