Submission #236386

# Submission time Handle Problem Language Result Execution time Memory
236386 2020-06-01T17:39:20 Z gurkot Type Printer (IOI08_printer) C++14
60 / 100
1000 ms 3660 KB
#include <iostream>
#include <algorithm>
#include <cstring>
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;

char ss[22];

main(){
 
 scanf("%d",&n);
 for (int i=0;i<n;i++) {
  scanf("%s",ss); l=strlen(ss);
  for (int j=0;j<l;j++) word[i].s+=ss[j];  
  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";
 }
 
 printf("%d\n",S.size());
 for (int i=0;i<S.size();i++)
  printf("%c\n",S[i]);
}

/*
3
print
the
poem
*/

Compilation message

printer.cpp: In function 'bool operator<(Word, Word)':
printer.cpp:10:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<a.s.size();i++)
               ~^~~~~~~~~~~
printer.cpp:13:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<b.s.size();i++)
               ~^~~~~~~~~~~
printer.cpp:16:25: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  return ka<kb || ka==kb && a.s<b.s;
                  ~~~~~~~^~~~~~~~~~
printer.cpp: At global scope:
printer.cpp:24:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
printer.cpp: In function 'int main()':
printer.cpp:38: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:43: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:48: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:52:24: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::__cxx11::basic_string<char>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n",S.size());
                ~~~~~~~~^
printer.cpp:53:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<S.size();i++)
               ~^~~~~~~~~
printer.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
printer.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",ss); l=strlen(ss);
   ~~~~~^~~~~~~~~
# 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 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 6 ms 1152 KB Output is correct
2 Correct 9 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1280 KB Output is correct
2 Correct 21 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 1512 KB Output is correct
2 Execution timed out 1057 ms 1952 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 1988 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1052 ms 1924 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 3660 KB Time limit exceeded
2 Halted 0 ms 0 KB -