Submission #742691

# Submission time Handle Problem Language Result Execution time Memory
742691 2023-05-16T17:53:51 Z peteza Type Printer (IOI08_printer) C++14
50 / 100
39 ms 2392 KB
#include <bits/stdc++.h>
using namespace std;

int n;
vector<pair<string, int>> inp;
string x, lng;
string cur;
queue<char> q;

int main() {
    cin.tie(0) -> sync_with_stdio(0);
    cin >> n;
    for(int i=0;i<n;i++) {
        cin >> x;
        inp.emplace_back(x, -1);
        if(x.size() > lng.size()) lng = x;
    }
    for(int i=0;i<n;i++) {
        for(int j=0;j<inp[i].first.size();j++) {
            if(inp[i].first[j] != lng[j]) {
                inp[i].second = j;
                break;
            }
        }
        if(inp[i].second == -1) inp[i].second = x.size();
    }
    sort(inp.begin(), inp.end(), [](pair<string, int> a, pair<string, int> b){
        if(a.second == b.second) return a.first < b.first;
        else return a.second < b.second;
    });
    for(int i=0;i<n;i++) {
        while(inp[i].first.substr(0, cur.size()) != cur) cur.pop_back(), q.push('-');
        for(int j=cur.size();j<inp[i].first.size();j++) cur += inp[i].first[j], q.push(inp[i].first[j]);
        q.push('P');
    }
    cout << q.size() << '\n';
    while(!q.empty()) cout << q.front() << '\n', q.pop();
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:19:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         for(int j=0;j<inp[i].first.size();j++) {
      |                     ~^~~~~~~~~~~~~~~~~~~~
printer.cpp:33:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for(int j=cur.size();j<inp[i].first.size();j++) cur += inp[i].first[j], q.push(inp[i].first[j]);
      |                              ~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 1172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 2280 KB Output isn't correct
2 Halted 0 ms 0 KB -