Submission #970452

# Submission time Handle Problem Language Result Execution time Memory
970452 2024-04-26T14:37:41 Z jadai007 Type Printer (IOI08_printer) C++14
100 / 100
86 ms 4708 KB
#include <bits/stdc++.h>

using namespace std;

int n, dif, ans;
string s[25010];
string l;

int diff(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) {
    int diff1 = diff(s1, l);
    int diff2 = diff(s2, l);
    if(diff1 == diff2) return s1 < s2;
    return diff1 < diff2;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n;
    for(int i=1; i<=n; i++) {
        cin >> s[i];
        if(s[i].size() > l.size()) l = s[i];
    }
    sort(s+1, s+n+1, cmp);
    for(int i=1; i<=n; i++) {
        dif = diff(s[i-1], s[i]);
        ans += s[i-1].size() + s[i].size() - 2*dif;
    }
    cout << ans + n << "\n";
    for(int i=1; i<=n; i++) {
        dif = diff(s[i-1], s[i]);
        for(int j=s[i-1].size(); j>dif; j--) cout << "-\n";
        for(int j=dif; j<s[i].size(); j++) cout << s[i][j] << "\n";
        cout << "P\n";
    }
}

Compilation message

printer.cpp: In function 'int diff(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++) if(s1[i] != s2[i]) return i;
      |              ~^~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:38:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for(int j=dif; j<s[i].size(); j++) cout << s[i][j] << "\n";
      |                        ~^~~~~~~~~~~~
# 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 1112 KB Output is correct
2 Correct 1 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 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 1368 KB Output is correct
2 Correct 15 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1612 KB Output is correct
2 Correct 28 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 2132 KB Output is correct
2 Correct 81 ms 3916 KB Output is correct
3 Correct 70 ms 3460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 1872 KB Output is correct
2 Correct 86 ms 4708 KB Output is correct
3 Correct 73 ms 3668 KB Output is correct
4 Correct 85 ms 4424 KB Output is correct