Submission #900656

# Submission time Handle Problem Language Result Execution time Memory
900656 2024-01-08T19:55:57 Z vanea Type Printer (IOI08_printer) C++14
30 / 100
66 ms 40424 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 = 0, sus = 0;
    for(int i = 0; i < ans.size(); i++) {
        if(ans[i] == '-') {
            sus++;
            curr--;
            if(curr == 0) {
                if(sus > mx) {
                    mx = sus;
                    idx = i;
                }
            }
        }
        else {
            if(ans[i] != 'P') curr++;
            sus = 0;
        }
    }
    cout << ans.size()-mx << '\n';
    for(int i = idx+1; 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:65:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for(int i = idx+1; i < ans.size(); i++) {
      |                        ~~^~~~~~~~~~~~
# 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 Correct 1 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 Output isn't correct
3 Halted 0 ms 0 KB -
# 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 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3060 KB Output is correct
2 Incorrect 9 ms 6488 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 7388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 17880 KB Output is correct
2 Correct 66 ms 40424 KB Output is correct
3 Incorrect 35 ms 20948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 14032 KB Output isn't correct
2 Halted 0 ms 0 KB -