Submission #900655

# Submission time Handle Problem Language Result Execution time Memory
900655 2024-01-08T19:47:20 Z vanea Type Printer (IOI08_printer) C++14
30 / 100
66 ms 40400 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int mxN = 5e5+10;

int trie[mxN][26];
int cnt = 0;
bool stop[mxN];
string alpha = "abcdefghijklmnopqrstuvwxyz";

void insert(string s) {
    int node = 0;
    for(auto c : s) {
        if(trie[node][c-'a'] == 0) trie[node][c-'a'] = ++cnt;
        node = trie[node][c-'a'];
    }
    stop[node] = true;
}

vector<char> ans;

void dfs(int node) {
    if(stop[node]) ans.push_back('P');
    for(auto c : alpha) {
        int k = trie[node][c-'a'];
        if(k) {
            ans.push_back(c);
            dfs(k);
            ans.push_back('-');
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        insert(s);
    }
    dfs(0);
    int curr = 0, mx = 0, idx;
    for(int i = 0; i < ans.size(); i++) {
        if(ans[i] == '-') curr++;
        else {
            if(curr > mx) {
                mx = curr;
                idx = i;
            }
            curr = 0;
        }
    }
    if(curr > mx) {
        mx = curr;
        idx = ans.size();
    }
    cout << ans.size() - mx << '\n';
    for(int i = idx; i < ans.size(); i++) {
        cout << ans[i] << '\n';
    }
    for(int i = 0; i < idx-mx; i++) {
        cout << ans[i] << '\n';
    }
    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:48:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i = 0; i < ans.size(); i++) {
      |                    ~~^~~~~~~~~~~~
printer.cpp:63:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for(int i = idx; i < ans.size(); i++) {
      |                      ~~^~~~~~~~~~~~
printer.cpp:66:27: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |     for(int i = 0; i < idx-mx; i++) {
      |                        ~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB printed invalid word
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3164 KB Output is correct
2 Incorrect 9 ms 6236 KB printed invalid word
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 7388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 17844 KB Output is correct
2 Correct 66 ms 40400 KB Output is correct
3 Incorrect 37 ms 21200 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 14032 KB Output isn't correct
2 Halted 0 ms 0 KB -