Submission #1026261

# Submission time Handle Problem Language Result Execution time Memory
1026261 2024-07-17T18:35:11 Z Nicolaikrob Type Printer (IOI08_printer) C++17
0 / 100
1000 ms 203016 KB
#include <bits/stdc++.h>
using namespace std;

string lgst;
vector<char> O;
unordered_map<string, int> M;

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

void dfs(string s) {
    if(!M[s]) return;
    int ln = s.size();
    O.push_back(s[ln-1]);
    for(int i = 'a'; i <= 'z'; i++) {
        if(i == lgst[ln]) continue;
        dfs(s+char(i));
    }
    dfs(s+char(lgst[ln]));
    if(M[s] == 2) O.push_back('P');
    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;
    dfs("");
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:34:24: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |         if(W[i].size() > ml) lgst = W[i], ml = W[i].size();
      |            ~~~~~~~~~~~~^~~~
printer.cpp:39:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for(int j = 0; j < W[i].size(); j++) {
      |                        ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1372 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 15556 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 214 ms 47876 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 947 ms 128464 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1058 ms 203016 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1050 ms 195532 KB Time limit exceeded
2 Halted 0 ms 0 KB -