Submission #440456

# Submission time Handle Problem Language Result Execution time Memory
440456 2021-07-02T10:03:17 Z dxz05 Type Printer (IOI08_printer) C++14
30 / 100
535 ms 4988 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 3e2;

string str[MAXN];

int main(){
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    int ind = 0;
    for (int i = 1; i <= n; i++){
        cin >> str[i];
        if (str[i].size() > str[ind].size()) ind = i;
    }

    string longest = str[ind];

    for (int i = 1; i <= n; i++){
        if (str[i][0] == longest[0]){
            str[i] = "{" + str[i];
        }
    }

    sort(str + 1, str + n + 1);

    vector<char> ans;
    for (int it = 1; it <= n; it++){
        if (str[it][0] == '{') str[it].erase(0, 1);
        string s = str[it], t = str[it - 1];

        while (t.size() > s.size()){
            ans.push_back('-');
            t.pop_back();
        }

        int cnt = 0;
        for (int i = 0; i < t.size(); i++){
            if (i < s.size() && t[i] == s[i]) cnt++; else
                break;
        }

        while (t.size() > cnt){
            t.pop_back();
            ans.push_back('-');
        }

        for (int i = cnt; i < s.size(); i++){
            ans.push_back(s[i]);
        }
        ans.push_back('P');

    }

    cout << ans.size() << endl;
    for (char c : ans) cout << c << endl;

    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:42:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for (int i = 0; i < t.size(); i++){
      |                         ~~^~~~~~~~~~
printer.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |             if (i < s.size() && t[i] == s[i]) cnt++; else
      |                 ~~^~~~~~~~~~
printer.cpp:47:25: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |         while (t.size() > cnt){
      |                ~~~~~~~~~^~~~~
printer.cpp:52:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for (int i = cnt; i < s.size(); i++){
      |                           ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3460 KB Output is correct
2 Correct 3 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Incorrect 2 ms 3404 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3652 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 3404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 3536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 83 ms 3720 KB Output is correct
2 Incorrect 181 ms 4108 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 211 ms 4032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 535 ms 4988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 430 ms 4668 KB Output isn't correct
2 Halted 0 ms 0 KB -