Submission #739858

# Submission time Handle Problem Language Result Execution time Memory
739858 2023-05-11T12:29:13 Z Desh03 Type Printer (IOI08_printer) C++17
0 / 100
10 ms 2260 KB
#include <bits/stdc++.h>
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, t = 0, p;
    cin >> n;
    vector<string> s(n);
    vector<char> ans;
    for (string &x : s) cin >> x;
    sort(s.begin(), s.end(), [&] (const string &s1, const string &s2) {
        return s1.size() == s2.size() ? s1 < s2 : s1.size() < s2.size();
    });
    string cur;
    while (1) {
        while (cur != s[t]) {
            cur.push_back(s[t][p]);
            ans.push_back(s[t][p++]);
        }
        ans.push_back('P');
        if (t == n - 1) break;
        t++;
        while (cur.substr(0, p) != s[t].substr(0, p)) {
            ans.push_back('-');
            cur.pop_back(), --p;
        }
    }
    cout << ans.size() << '\n';
    for (int i = 0; i < ans.size(); i++) cout << ans[i] << '\n';
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for (int i = 0; i < ans.size(); i++) cout << ans[i] << '\n';
      |                     ~~^~~~~~~~~~~~
printer.cpp:19:33: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   19 |             ans.push_back(s[t][p++]);
      |                                ~^~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 448 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 724 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 1108 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 2244 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 2260 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -