Submission #964376

# Submission time Handle Problem Language Result Execution time Memory
964376 2024-04-16T18:00:12 Z anango Type Printer (IOI08_printer) C++17
100 / 100
988 ms 7744 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

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

signed main() {
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<string> v;
    int ma=0;
    int mpos=-1;
    vector<int> answers(n);
    for (int i=0; i<n; i++) {
        string s;
        cin >> s;
        v.push_back(s);
        if (s.size()>ma) {
            ma=s.size();
            mpos=i;
        }
    }
    string mword=v[mpos];
    for (int i=0; i<n; i++) {
        answers[i] = pref(v[i], mword);
    }
    vector<int> w;
    for (int i=0; i<n; i++) {
        w.push_back(i);
    }
    sort(w.begin(), w.end(), [&](const int s1, const int s2) {

        if (answers[s1]!=answers[s2]) {
            return answers[s1]<answers[s2];
        }
        return v[s1]<v[s2];
    });
    vector<string> v2(n);
    for (int i=0; i<n; i++) {
        v2[i] = v[w[i]];
    }
    int tot=0;
    string prints;
    string current;
    for (int i=0; i<n; i++) {
        int t=pref(current,v2[i]);
        while (current.size()>t) {
            prints.append("-");
            current.pop_back();
        }

        prints.append(v2[i].substr(current.size(), v2[i].size()-current.size()));
        current = v2[i];


        prints.append("P");
    }
    cout << prints.size() << endl;
    for (auto i:prints) {
        cout << i << endl;
    }
}

Compilation message

printer.cpp: In function 'long long int pref(std::string, std::string)':
printer.cpp:6:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |     for (int i=0; i<s1.size(); i++) {
      |                   ~^~~~~~~~~~
printer.cpp:7:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |         if (i>=s2.size() || s1[i]!=s2[i]) {
      |             ~^~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:29:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   29 |         if (s.size()>ma) {
      |             ~~~~~~~~^~~
printer.cpp:58:30: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   58 |         while (current.size()>t) {
      |                ~~~~~~~~~~~~~~^~
printer.cpp:53:9: warning: unused variable 'tot' [-Wunused-variable]
   53 |     int tot=0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 356 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 11 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 348 KB Output is correct
2 Correct 26 ms 624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 1176 KB Output is correct
2 Correct 124 ms 1384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 161 ms 2044 KB Output is correct
2 Correct 53 ms 1788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 384 ms 3712 KB Output is correct
2 Correct 856 ms 6096 KB Output is correct
3 Correct 441 ms 5600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 347 ms 3652 KB Output is correct
2 Correct 988 ms 7172 KB Output is correct
3 Correct 524 ms 6632 KB Output is correct
4 Correct 940 ms 7744 KB Output is correct