Submission #1040963

# Submission time Handle Problem Language Result Execution time Memory
1040963 2024-08-01T12:55:25 Z ArthuroWich Type Printer (IOI08_printer) C++17
100 / 100
813 ms 51092 KB
#include <bits/stdc++.h>
using namespace std;
int trie[20*25005][26], le[20*25005], co = 1, en[20*25005];
vector<char> ans;
void insert(string s) {
    int n = 0;
    for (int i = 0; i < s.length(); i++) { 
        char c = s[i];
        if (!trie[n][c-'a']) {
            trie[n][c-'a'] = co;
            co++;
        }
        le[trie[n][c-'a']] = max(le[trie[n][c-'a']], (int)s.length()-i);
        n = trie[n][c-'a'];
    }
    en[n] = 1;
}
void dfs(int a) {
    if (en[a]) {
        ans.push_back('P');
    }
    vector<pair<int, int>> v;
    for (int i = 0; i < 26; i++) {
        if (trie[a][i]) {
            v.push_back({le[trie[a][i]], i});
        }
    }
    sort(v.begin(), v.end());
    for (auto [_, i] : v) {
        ans.push_back((char)(i+'a'));
        dfs(trie[a][i]);
        ans.push_back('-');
    }
}
void solve() {
    int n;
    cin >> n;   
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        insert(s);
    }
    dfs(0);
    while(!ans.empty() && ans.back() == '-') {
        ans.pop_back();
    }
    cout << ans.size() << endl;
    for (char c : ans) {
        cout << c << endl;
    }
}
int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    t = 1;
    while(t--) {
        solve();
    }
}

Compilation message

printer.cpp: In function 'void insert(std::string)':
printer.cpp:7:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |     for (int i = 0; i < s.length(); 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 0 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 344 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 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 7 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1112 KB Output is correct
2 Correct 22 ms 1480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 3160 KB Output is correct
2 Correct 100 ms 6736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 7768 KB Output is correct
2 Correct 37 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 282 ms 19032 KB Output is correct
2 Correct 675 ms 42956 KB Output is correct
3 Correct 332 ms 22160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 238 ms 14792 KB Output is correct
2 Correct 766 ms 51092 KB Output is correct
3 Correct 420 ms 25300 KB Output is correct
4 Correct 813 ms 48332 KB Output is correct