Submission #966691

# Submission time Handle Problem Language Result Execution time Memory
966691 2024-04-20T08:23:31 Z vjudge1 Type Printer (IOI08_printer) C++14
100 / 100
88 ms 4684 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
string maxi="";
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;
}
static bool cmp(string&a,string&b) {
    int x=pref(a,maxi);
    int y=pref(b,maxi);
    if (a == maxi) {
        return false;
    }
    if (b == maxi) {
        return true;
    }
    if (x != y) {
        return x<y;
    }
    return a < b;
}
int main() {
    ll n;
    cin >> n;
    vector<string> p(n+1);
    for (int i=1;i<=n;i++) {
        cin >> p[i];
        if (p[i].size() > maxi.size()) {
            maxi = p[i];
        }
    }
    
    sort(p.begin()+1,p.end(),cmp);
    int pr,mx=0;
    for(int i=1; i<=n; i++) {
        pr = pref(p[i-1], p[i]);
        mx += p[i-1].size() + p[i].size() - 2*pr;
    }
    cout << mx+n << "\n";
    for(int i=1; i<=n; i++) {
        pr = pref(p[i-1], p[i]);
        for(int j=p[i-1].size(); j>pr; j--) {
            cout << "-\n";
        }
        for(int j=pr; j<p[i].size(); j++) {
            cout << p[i][j] << "\n";
        }
        cout << "P\n";
    }
    return 0;
}

Compilation message

printer.cpp: In function 'int pref(std::string, std::string)':
printer.cpp:7:15: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
    7 |     for(i=0; i<min(s1.size(), s2.size()); i++) {
      |              ~^~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:49:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(int j=pr; j<p[i].size(); j++) {
      |                       ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 604 KB Output is correct
2 Correct 14 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 860 KB Output is correct
2 Correct 22 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 1876 KB Output is correct
2 Correct 74 ms 3912 KB Output is correct
3 Correct 61 ms 3152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1828 KB Output is correct
2 Correct 88 ms 4684 KB Output is correct
3 Correct 74 ms 3632 KB Output is correct
4 Correct 86 ms 4420 KB Output is correct