Submission #870368

# Submission time Handle Problem Language Result Execution time Memory
870368 2023-11-07T13:37:58 Z Essa2006 Type Printer (IOI08_printer) C++14
100 / 100
465 ms 43284 KB
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin>>n;
    vector<string>A(n);
    string a="", last="";
    map<string, bool>mp;
    for(int i=0;i<n;i++){
        cin>>A[i];
        if(A[i].size()>a.size())
            a=A[i];
        mp[A[i]]=1;
    }
    sort(A.begin(), A.end());
    vector<char>Ans;
    for(int f=0;f<=a.size();f++){
        for(int i=0;i<n;i++){
            if(mp[A[i]] && ((A[i].size()>f && A[i][f]!=a[f]) || f==a.size())){
                int cur=last.size()-1, j=-1;
                while(j+1<min(last.size(), A[i].size()) && last[j+1]==A[i][j+1])
                    j++;
                while(cur>j)
                    Ans.push_back('-'), cur--, last.pop_back();
                j++;
                while(j<A[i].size()){
                    Ans.push_back(A[i][j]), last.push_back(A[i][j++]);
                    if(mp[last])
                        Ans.push_back('P'), mp[last]=0;
                }
            }
        }
    }
    cout<<Ans.size()<<'\n';
    for(int i=0;i<Ans.size();i++){
        cout<<Ans[i]<<'\n';
    }
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int f=0;f<=a.size();f++){
      |                 ~^~~~~~~~~~
printer.cpp:20:41: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |             if(mp[A[i]] && ((A[i].size()>f && A[i][f]!=a[f]) || f==a.size())){
      |                              ~~~~~~~~~~~^~
printer.cpp:20:66: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |             if(mp[A[i]] && ((A[i].size()>f && A[i][f]!=a[f]) || f==a.size())){
      |                                                                 ~^~~~~~~~~~
printer.cpp:22:26: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   22 |                 while(j+1<min(last.size(), A[i].size()) && last[j+1]==A[i][j+1])
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:27:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |                 while(j<A[i].size()){
      |                       ~^~~~~~~~~~~~
printer.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i=0;i<Ans.size();i++){
      |                 ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 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 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 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 3 ms 788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 860 KB Output is correct
2 Correct 8 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2640 KB Output is correct
2 Correct 47 ms 5376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 6092 KB Output is correct
2 Correct 44 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 164 ms 15368 KB Output is correct
2 Correct 387 ms 36296 KB Output is correct
3 Correct 217 ms 19660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 127 ms 11664 KB Output is correct
2 Correct 465 ms 43284 KB Output is correct
3 Correct 334 ms 21964 KB Output is correct
4 Correct 401 ms 40260 KB Output is correct