Submission #1039378

# Submission time Handle Problem Language Result Execution time Memory
1039378 2024-07-30T19:27:50 Z ThommyDB Type Printer (IOI08_printer) C++17
20 / 100
29 ms 2340 KB
#include<bits/stdc++.h>

using namespace std;

int n;
vector<string> words;
string largest_word, ans;

bool compare(string x, string y){
    int a = 0;
    for(int i = 0; i < x.size(); i++){
        if(x[i]!=largest_word[i]){
            a=i;
            break;
        }
        if(i==x.size()-1)a=x.size();
    }
    int b = 0;
    for(int i = 0; i < y.size(); i++){
        if(y[i]!=largest_word[i]){
            b=i;
            break;
        }
        if(i==y.size()-1)b=y.size();
    }
    return a==b ? x < y : a < b;
}

signed main(){
    cin >> n;
    words.resize(n);
    for(int i = 0; i < n; i++){
        cin >> words[i];
        if(largest_word.size() < words[i].size()) largest_word = words[i]; 
    }
    sort(words.begin(), words.end(), compare);
    ans = words[0] + 'P';
    for(int i = 1; i < n; i++){
        string& a = words[i-1];
        string& b = words[i];
        int hold;
        for(int j = 0; j < min(a.size(), b.size()); j++){
            if(a[j]!=b[j]){
                hold = j;
                break;
            }
        }
        for(int j = a.size()-1; j >= hold; j--) ans.push_back('-');
        for(int j = hold; j < b.size(); j++) ans.push_back(b[j]);
        ans.push_back('P');
    }
    cout << ans.size() << "\n";
    for(auto u : ans){
        cout << u << "\n";
    }
}

Compilation message

printer.cpp: In function 'bool compare(std::string, std::string)':
printer.cpp:11:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i = 0; i < x.size(); i++){
      |                    ~~^~~~~~~~~~
printer.cpp:16:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |         if(i==x.size()-1)a=x.size();
      |            ~^~~~~~~~~~~~
printer.cpp:19:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i = 0; i < y.size(); i++){
      |                    ~~^~~~~~~~~~
printer.cpp:24:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         if(i==y.size()-1)b=y.size();
      |            ~^~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:42:26: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   42 |         for(int j = 0; j < min(a.size(), b.size()); j++){
      |                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:49:29: 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 = hold; j < b.size(); j++) ans.push_back(b[j]);
      |                           ~~^~~~~~~~~~
printer.cpp:48:35: warning: 'hold' may be used uninitialized in this function [-Wmaybe-uninitialized]
   48 |         for(int j = a.size()-1; j >= hold; j--) ans.push_back('-');
      |                                 ~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
# 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 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 1168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 2340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 2292 KB Output isn't correct
2 Halted 0 ms 0 KB -