Submission #440480

# Submission time Handle Problem Language Result Execution time Memory
440480 2021-07-02T10:15:02 Z dxz05 Type Printer (IOI08_printer) C++14
80 / 100
1000 ms 7068 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

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++){
        int j = 0;
        while (j < str[i].size() && j < longest.size() && str[i][j] == longest[j]) j++;
        str[i] = string(j, '{') + str[i];
    }

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

    vector<char> ans;
    for (int it = 1; it <= n; it++){
        int j = 0;
        while (j < str[it].size() && str[it][j] == '{') j++;
        str[it].erase(0, j);

        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:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         while (j < str[i].size() && j < longest.size() && str[i][j] == longest[j]) j++;
      |                ~~^~~~~~~~~~~~~~~
printer.cpp:26:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         while (j < str[i].size() && j < longest.size() && str[i][j] == longest[j]) j++;
      |                                     ~~^~~~~~~~~~~~~~~~
printer.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         while (j < str[it].size() && str[it][j] == '{') j++;
      |                ~~^~~~~~~~~~~~~~~~
printer.cpp:46:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for (int i = 0; i < t.size(); i++){
      |                         ~~^~~~~~~~~~
printer.cpp:47:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |             if (i < s.size() && t[i] == s[i]) cnt++; else
      |                 ~~^~~~~~~~~~
printer.cpp:51:25: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |         while (t.size() > cnt){
      |                ~~~~~~~~~^~~~~
printer.cpp:56:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         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 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Correct 3 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3404 KB Output is correct
2 Correct 14 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3404 KB Output is correct
2 Correct 29 ms 3524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 3656 KB Output is correct
2 Correct 204 ms 3912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 204 ms 3924 KB Output is correct
2 Correct 63 ms 3660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 519 ms 4844 KB Output is correct
2 Execution timed out 1082 ms 6788 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 427 ms 4384 KB Output is correct
2 Execution timed out 1087 ms 7068 KB Time limit exceeded
3 Halted 0 ms 0 KB -