Submission #966641

# Submission time Handle Problem Language Result Execution time Memory
966641 2024-04-20T07:33:20 Z vjudge1 Type Printer (IOI08_printer) C++17
100 / 100
84 ms 4692 KB
#include <bits/stdc++.h>

using namespace std;

int n, pr1, pr2, pr, mx;
string arr[25010];
string l;

int pref(string s1, string s2) {
    int i;
    for(i=0; i<min(s1.size(), s2.size()); i++) {
        if(s1[i] != s2[i]) return i;
    }
    return i;
}

bool cmp(string s1, string s2) {
    pr1 = pref(s1, l);
    pr2 = pref(s2, l);
    if(pr1 == pr2) return s1 < s2;
    return pr1 < pr2;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for(int i=1; i<=n; i++) {
        cin >> arr[i];
        if(arr[i].size() > l.size()) {
            l = arr[i];
        }
    }
    sort(arr+1, arr+n+1, cmp);
    for(int i=1; i<=n; i++) {
        pr = pref(arr[i-1], arr[i]);
        mx += arr[i-1].size() + arr[i].size() - 2*pr;
    }
    cout << mx+n << "\n";
    for(int i=1; i<=n; i++) {
        pr = pref(arr[i-1], arr[i]);
        for(int j=arr[i-1].size(); j>pr; j--) {
            cout << "-\n";
        }
        for(int j=pr; j<arr[i].size(); j++) {
            cout << arr[i][j] << "\n";
        }
        cout << "P\n";
    }
    
}

Compilation message

printer.cpp: In function 'int pref(std::string, std::string)':
printer.cpp:11:15: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   11 |     for(i=0; i<min(s1.size(), s2.size()); i++) {
      |              ~^~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:44:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for(int j=pr; j<arr[i].size(); j++) {
      |                       ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 3 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1372 KB Output is correct
2 Correct 15 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1512 KB Output is correct
2 Correct 25 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 2168 KB Output is correct
2 Correct 76 ms 3916 KB Output is correct
3 Correct 64 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 1876 KB Output is correct
2 Correct 84 ms 4692 KB Output is correct
3 Correct 72 ms 3668 KB Output is correct
4 Correct 84 ms 4428 KB Output is correct