Submission #1026288

# Submission time Handle Problem Language Result Execution time Memory
1026288 2024-07-17T18:57:21 Z Nicolaikrob Type Printer (IOI08_printer) C++17
80 / 100
1000 ms 204724 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

string lgst, s, O;
unordered_map<string, int> M;

void out() {
    cout << O.size() << '\n';
    for(auto x : O) cout << x << '\n';
    exit(0);
}

void dfs() {
    if(!M[s]) return;
    int ln = s.size();
    if(ln) O.push_back(s[ln-1]);
    if(M[s] == 2) O.push_back('P');
    for(int i = 'a'; i <= 'z'; i++) {
        if(i == lgst[ln]) continue;
        s += char(i);
        dfs();
        s.pop_back();
    }
    s += char(lgst[ln]);
    dfs();
    s.pop_back();
    if(s+'.' == lgst) out();
    O.push_back('-');
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<string> W(n); for(auto &x : W) cin >> x;
    int ml = 0;
    for(int i = 0; i < n; i++) {
        if(W[i].size() > ml) lgst = W[i], ml = W[i].size();
    }
    lgst += '.';
    for(int i = 0; i < n; i++) {
        string t = "";
        for(int j = 0; j < W[i].size(); j++) {
            t += W[i][j];
            M[t] = max(M[t], 1);
        }
        M[t] = 2;
    }
    M[""] = 1;
    s = "";
    dfs();
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:40:24: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |         if(W[i].size() > ml) lgst = W[i], ml = W[i].size();
      |            ~~~~~~~~~~~~^~~~
printer.cpp:45:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for(int j = 0; j < W[i].size(); j++) {
      |                        ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1372 KB Output is correct
2 Correct 18 ms 8060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 15820 KB Output is correct
2 Correct 46 ms 17536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 176 ms 48064 KB Output is correct
2 Correct 660 ms 104696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 909 ms 128688 KB Output is correct
2 Correct 82 ms 27776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 204724 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1022 ms 187724 KB Time limit exceeded
2 Halted 0 ms 0 KB -