Submission #871833

# Submission time Handle Problem Language Result Execution time Memory
871833 2023-11-11T17:16:01 Z Matjaz Type Printer (IOI08_printer) C++14
10 / 100
457 ms 2544 KB
//
//  IOI2008Printer.cpp
//  
//
//  Created by Matjaz Leonardis on 11/11/2023.
//

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

int main(){
    
    int N;
    cin >> N;
    vector<string> s(N+1);
    for (int i=0;i<N;i++) cin >> s[i];
    s[N] = "";
    
    int max_len = 0;
    int max_index = -1;
    for (int i=0;i<=N;i++) if (s[i].size() > max_len){
        max_len = s[i].size();
        max_index = i;
    }
    
    string target = s[max_index];
    
    for (int i=0;i<=N;i++){
        for (int j=0;j<s[i].size();j++){
            if (s[i][j] != target[j]) s[i][j] -= 26;
        }
    }
    
    sort(s.begin(), s.end());
    
    string ans = "";
    
    for (int i=1;i<=N;i++){
        int l = shared_prefix_length(s[i-1], s[i]);
        for (int j=l;j<s[i-1].size();j++) ans.push_back('-');
        for (int j=l;j<s[i].size();j++){
            if (s[i][j] < 'a') s[i][j] += 26;
            ans.push_back(s[i][j]);
        }
        ans.push_back('P');
    }
    
    cout << ans.size() << endl;
    for (int i=0;i<ans.size();i++) cout << ans[i] << endl;
    
    return 0;
}

Compilation message

printer.cpp: In function 'int shared_prefix_length(std::string, std::string)':
printer.cpp:18:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         if (i >= s1.size()) return s1.size();
      |             ~~^~~~~~~~~~~~
printer.cpp:19:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         if (i >= s2.size()) return s2.size();
      |             ~~^~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:34:44: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |     for (int i=0;i<=N;i++) if (s[i].size() > max_len){
      |                                ~~~~~~~~~~~~^~~~~~~~~
printer.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for (int j=0;j<s[i].size();j++){
      |                      ~^~~~~~~~~~~~
printer.cpp:53:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for (int j=l;j<s[i-1].size();j++) ans.push_back('-');
      |                      ~^~~~~~~~~~~~~~
printer.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int j=l;j<s[i].size();j++){
      |                      ~^~~~~~~~~~~~
printer.cpp:62:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for (int i=0;i<ans.size();i++) cout << ans[i] << endl;
      |                  ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 500 KB Output is correct
2 Correct 1 ms 756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 70 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 197 ms 1256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 457 ms 2544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 434 ms 2284 KB Output isn't correct
2 Halted 0 ms 0 KB -