답안 #522750

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
522750 2022-02-05T16:02:08 Z Jesus Type Printer (IOI08_printer) C++14
90 / 100
1000 ms 4956 KB
#include <bits/stdc++.h>

using namespace std;

string palabra[25002];

vector<char> res;

int main()
{
    ios_base::sync_with_stdio();cin.tie(0);
    int n;
    cin>>n;
    string mayor,aux,aux2;
    for(int i=0;i<n;i++){
        cin>>palabra[i];
        if(palabra[i].size()>mayor.size()) mayor=palabra[i];
    }
    sort(palabra,palabra+n);
    int i=0,j=n-1,x,y,auxi,auxj;
    int w,z,pos=0;
    while(pos<mayor.size()){
        x=i; y=j;
        auxi=i; auxj=j;
        while(x<=y){
            z=(x+y)/2;
            aux=palabra[z];
            if(aux[pos]==mayor[pos]){
                w=z;
                y=z-1;
            }
            else if(aux[pos]<mayor[pos]) x=z+1;
            else y=z-1;
        }
        x=i; y=j;
        i=w;
        while(x<=y){
            z=(x+y)/2;
            aux=palabra[z];
            if(aux[pos]==mayor[pos]){
                j=z;
                x=z+1;
            }
            else if(aux[pos]<mayor[pos]) x=z+1;
            else y=z-1;
        }
        for(z=auxi;z<i;z++){
            if(z==auxi){
                aux=palabra[z];
                for(int k=pos;k<aux.size();k++){
                    res.push_back(aux[k]);
                }
                res.push_back('P');
            }
            else{
                aux2=palabra[z];
                int k=pos;
                for(k;k<aux.size();k++){
                    if(aux2[k]!=aux[k]) break;
                }
                for(int l=k;l<aux.size();l++){
                    res.push_back('-');
                }
                for(k;k<aux2.size();k++){
                    res.push_back(aux2[k]);
                }
                res.push_back('P');
                aux=aux2;
            }
            if(z==i-1){
                for(int k=pos;k<aux.size();k++){
                    res.push_back('-');
                }
            }
        }
        for(z=j+1;z<=auxj;z++){
            if(z==j+1){
                aux=palabra[z];
                for(int k=pos;k<aux.size();k++){
                    res.push_back(aux[k]);
                }
                res.push_back('P');
            }
            else{
                aux2=palabra[z];
                int k=pos;
                for(k;k<aux.size();k++){
                    if(aux2[k]!=aux[k]) break;
                }
                for(int l=k;l<aux.size();l++){
                    res.push_back('-');
                }
                for(k;k<aux2.size();k++){
                    res.push_back(aux2[k]);
                }
                res.push_back('P');
                aux=aux2;
            }
            if(z==auxj){
                for(int k=pos;k<aux.size();k++){
                    res.push_back('-');
                }
            }
        }
        res.push_back(mayor[pos]);
        if(palabra[i].size()==pos+1){
            res.push_back('P');
            i++;
        }
        pos++;
    }
    cout<<res.size()<<endl;
    for(char l:res){
        cout<<l<<endl;
    }
    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:22:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     while(pos<mayor.size()){
      |           ~~~^~~~~~~~~~~~~
printer.cpp:50:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |                 for(int k=pos;k<aux.size();k++){
      |                               ~^~~~~~~~~~~
printer.cpp:58:21: warning: statement has no effect [-Wunused-value]
   58 |                 for(k;k<aux.size();k++){
      |                     ^
printer.cpp:58:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |                 for(k;k<aux.size();k++){
      |                       ~^~~~~~~~~~~
printer.cpp:61:30: 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 l=k;l<aux.size();l++){
      |                             ~^~~~~~~~~~~
printer.cpp:64:21: warning: statement has no effect [-Wunused-value]
   64 |                 for(k;k<aux2.size();k++){
      |                     ^
printer.cpp:64:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |                 for(k;k<aux2.size();k++){
      |                       ~^~~~~~~~~~~~
printer.cpp:71:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |                 for(int k=pos;k<aux.size();k++){
      |                               ~^~~~~~~~~~~
printer.cpp:79:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |                 for(int k=pos;k<aux.size();k++){
      |                               ~^~~~~~~~~~~
printer.cpp:87:21: warning: statement has no effect [-Wunused-value]
   87 |                 for(k;k<aux.size();k++){
      |                     ^
printer.cpp:87:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |                 for(k;k<aux.size();k++){
      |                       ~^~~~~~~~~~~
printer.cpp:90:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |                 for(int l=k;l<aux.size();l++){
      |                             ~^~~~~~~~~~~
printer.cpp:93:21: warning: statement has no effect [-Wunused-value]
   93 |                 for(k;k<aux2.size();k++){
      |                     ^
printer.cpp:93:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |                 for(k;k<aux2.size();k++){
      |                       ~^~~~~~~~~~~~
printer.cpp:100:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |                 for(int k=pos;k<aux.size();k++){
      |                               ~^~~~~~~~~~~
printer.cpp:106:29: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  106 |         if(palabra[i].size()==pos+1){
      |            ~~~~~~~~~~~~~~~~~^~~~~~~
printer.cpp:47:21: warning: 'w' may be used uninitialized in this function [-Wmaybe-uninitialized]
   47 |         for(z=auxi;z<i;z++){
      |                    ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 972 KB Output is correct
2 Correct 11 ms 1028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 1148 KB Output is correct
2 Correct 24 ms 1164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 1292 KB Output is correct
2 Correct 138 ms 1572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 196 ms 1600 KB Output is correct
2 Correct 52 ms 1352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 384 ms 2320 KB Output is correct
2 Correct 876 ms 4344 KB Output is correct
3 Correct 474 ms 3388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 324 ms 1924 KB Output is correct
2 Execution timed out 1091 ms 4956 KB Time limit exceeded
3 Halted 0 ms 0 KB -