Submission #969647

# Submission time Handle Problem Language Result Execution time Memory
969647 2024-04-25T12:01:15 Z SeenSiravit Type Printer (IOI08_printer) C++14
100 / 100
75 ms 5648 KB
#include<bits/stdc++.h>

using namespace std;

const int mxN = 25000 + 5;
int n;
string words[mxN];
string base = "";

bool cmp(string a , string b){
    int na = a.length() , nb = b.length();
    int idx_a = na , idx_b = nb;

    for(int i=0;i<na;i++){
        if(a[i] != base[i]){
            idx_a = i;
            break;
        }
    }

    for(int i=0;i<nb;i++){
        if(b[i] != base[i]){
            idx_b = i;
            break;
        }
    }

    if(idx_a==idx_b) return a < b;
    return idx_a < idx_b;
}

int main(){

    cin>> n;

    for(int i=0;i<n;i++){
        cin>> words[i];

        if(words[i].length() > base.length()) base = words[i];
    }

    // words[n-1] = base , cnt = len(base)
    sort(words, words + n , cmp);

    // for(auto word : words) cout<< word << "\n";

    string ans = "";
    for(auto c : words[0]) ans += c;
    ans += 'P';

    for(int i=1;i<n;i++){
        int idx = min(words[i-1].length()  ,words[i].length());
        for(int j=0;j<min(words[i-1].length() , words[i].length());j++){
            if(words[i-1][j] != words[i][j]){
                idx = j;
                break;
            }
        }

        for(int j=words[i-1].length()-1;j>=idx;j--) ans += '-';
        for(int j=idx;j<words[i].length();j++) ans += words[i][j];
        ans += 'P';
    }

    cout<< ans.length() << "\n";

    for(auto c : ans) cout<< c << "\n";

    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   53 |         for(int j=0;j<min(words[i-1].length() , words[i].length());j++){
      |                     ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:61:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for(int j=idx;j<words[i].length();j++) ans += words[i][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 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 2 ms 1116 KB Output is correct
2 Correct 2 ms 1312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1368 KB Output is correct
2 Correct 12 ms 1880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1604 KB Output is correct
2 Correct 18 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 2540 KB Output is correct
2 Correct 63 ms 4824 KB Output is correct
3 Correct 50 ms 3848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2016 KB Output is correct
2 Correct 75 ms 5648 KB Output is correct
3 Correct 59 ms 4336 KB Output is correct
4 Correct 75 ms 5384 KB Output is correct