Submission #236385

# Submission time Handle Problem Language Result Execution time Memory
236385 2020-06-01T17:30:23 Z gurkot Type Printer (IOI08_printer) C++11
60 / 100
1000 ms 3228 KB
#include <iostream>
#include <algorithm>
using namespace std;

string S;
struct Word{ string s;};
bool operator <(Word a, Word b){
 int ka=0,kb=0;
 for (int i=0;i<a.s.size();i++)
  if (a.s[i]==S[i]) ka++; 
            else break;
 for (int i=0;i<b.s.size();i++)
  if (b.s[i]==S[i]) kb++; 
            else break;
 return ka<kb || ka==kb && a.s<b.s;
} 
Word word[25001];

int n,lmax,l;


main(){
 ios::sync_with_stdio(0);
 cin>>n;
 for (int i=0;i<n;i++) {
  cin>>word[i].s;
  l=word[i].s.size();
  if (lmax<l){
  	lmax=l; S=word[i].s;
  }
 }
  
 sort(word,word+n); 
 S="";
 
 for (int i=0;i<word[0].s.size();i++) S=S+word[0].s[i];
 S=S+"P";
 
 for (int i=1;i<n;i++){
  int k=0;
  for (int j=0;j<min(word[i-1].s.size(),word[i].s.size());j++)
   if(word[i-1].s[j]==word[i].s[j]) k++; 
                             else break;
  l=word[i-1].s.size();
  for (int j=1;j<=l-k;j++) S=S+"-";
  for (int j=k;j<word[i].s.size();j++) S=S+word[i].s[j];
  S=S+"P";
 }
 
 cout<<S.size()<<endl;
 for (int i=0;i<S.size();i++)
  cout<<S[i]<<endl;
 
 
}

/*
3
print
the
poem
*/

Compilation message

printer.cpp: In function 'bool operator<(Word, Word)':
printer.cpp:9:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<a.s.size();i++)
               ~^~~~~~~~~~~
printer.cpp:12:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<b.s.size();i++)
               ~^~~~~~~~~~~
printer.cpp:15:25: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  return ka<kb || ka==kb && a.s<b.s;
                  ~~~~~~~^~~~~~~~~~
printer.cpp: At global scope:
printer.cpp:22:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
printer.cpp: In function 'int main()':
printer.cpp:36:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<word[0].s.size();i++) S=S+word[0].s[i];
               ~^~~~~~~~~~~~~~~~~
printer.cpp:41:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=0;j<min(word[i-1].s.size(),word[i].s.size());j++)
                ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:46:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=k;j<word[i].s.size();j++) S=S+word[i].s[j];
                ~^~~~~~~~~~~~~~~~~
printer.cpp:51:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<S.size();i++)
               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1152 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1152 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1152 KB Output is correct
2 Correct 7 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1152 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1152 KB Output is correct
2 Correct 24 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 1280 KB Output is correct
2 Correct 60 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 239 ms 1492 KB Output is correct
2 Execution timed out 1058 ms 2928 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 1832 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 2056 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1022 ms 3228 KB Time limit exceeded
2 Halted 0 ms 0 KB -