Submission #969640

# Submission time Handle Problem Language Result Execution time Memory
969640 2024-04-25T11:51:05 Z SeenSiravit Type Printer (IOI08_printer) C++14
20 / 100
32 ms 2440 KB
#include<bits/stdc++.h>

using namespace std;

int n;
vector<string> words;
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(){
    ios::sync_with_stdio(0),cin.tie(0);

    cin>> n;

    words.assign(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.begin() , words.end() , 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 = 0;
        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:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   55 |         for(int j=0;j<min(words[i-1].length() , words[i].length());j++){
      |                     ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:63:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for(int j=idx;j<words[i].length();j++) ans += words[i][j];
      |                       ~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 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 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 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 1260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 2440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 2380 KB Output isn't correct
2 Halted 0 ms 0 KB -