Submission #877013

#TimeUsernameProblemLanguageResultExecution timeMemory
877013StefanL2005Type Printer (IOI08_printer)C++14
100 / 100
42 ms5072 KiB
#include <bits/stdc++.h> using namespace std; struct LetterPoz{ int poz, length; }; bool rule(LetterPoz A, LetterPoz B) { if (A.length == B.length) return A.poz < B.poz; return A.length < B.length; } int Similarities(string A, string B) { int lA = A.length(), lB = B.length(), nr = 0; for (int i = 0; i < min(lA, lB); i++) if (A[i] == B[i]) nr++; else break; return nr; } void MoveBiggestLast (vector<string> &EndStrings, int MaxSize, vector<char> &Commands) { int GetPoz = 0; for (int i = 0; i < EndStrings.size(); i++) if (EndStrings[i].size() == MaxSize) GetPoz = i; vector<string> Str = EndStrings; int level = 1; string Last = ""; int nr = Str.size(); do { vector<string> Finishes; for (int i = 0; i < Str.size(); i++) { if (Str[i] == "") continue; if (EndStrings[GetPoz].substr(0, level) == Str[i].substr(0, level)) { if (Str[i].size() == level) { Finishes.push_back(Str[i]); Str[i] = ""; nr--; } continue; } int sim = Similarities(Str[i], Last); for (int j = 0; j < Last.length() - sim; j++) Commands.push_back('-'); for (int j = sim; j < Str[i].length(); j++) Commands.push_back(Str[i][j]); Commands.push_back('P'); Last = Str[i]; Str[i] = ""; nr--; } for (int i = 0; i < Finishes.size(); i++) { int sim = Similarities(Finishes[i], Last); for (int j = 0; j < Last.length() - sim; j++) Commands.push_back('-'); for (int j = sim; j < Finishes[i].length(); j++) Commands.push_back(Finishes[i][j]); Commands.push_back('P'); Last = Finishes[i]; } level++; }while (nr != 0); } int main() { ios_base :: sync_with_stdio(false); int N; cin>> N; vector<string> To_Print(N); vector<char> Commands; for (int i = 0; i < N; i++) cin>> To_Print[i]; sort(To_Print.begin(), To_Print.end()); char FinalLetter; int MaxSize = 0; for (int i = 0; i < N; i++) { if (To_Print[i].size() > MaxSize) { MaxSize = To_Print[i].size(); FinalLetter = To_Print[i][0]; } } string Last = ""; for (int i = 0; i < N; i++) { if (To_Print[i][0] == FinalLetter) continue; int sim = Similarities(To_Print[i], Last); for (int j = 0; j < Last.length()- sim; j++) Commands.push_back('-'); for (int j = sim; j < To_Print[i].length(); j++) Commands.push_back(To_Print[i][j]); Commands.push_back('P'); Last = To_Print[i]; } if (Last != "") for (int i = 0; i < Last.size(); i++) Commands.push_back('-'); vector<string> EndStrings; for (int i = 0; i < N; i++) if (To_Print[i][0] == FinalLetter) EndStrings.push_back(To_Print[i]); MoveBiggestLast(EndStrings, MaxSize, Commands); cout<< Commands.size() << "\n"; for (int i = 0; i < Commands.size(); i++) cout<< Commands[i] << "\n"; return 0; }

Compilation message (stderr)

printer.cpp: In function 'void MoveBiggestLast(std::vector<std::__cxx11::basic_string<char> >&, int, std::vector<char>&)':
printer.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int i = 0; i < EndStrings.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~~~~~
printer.cpp:32:34: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |         if (EndStrings[i].size() == MaxSize)
      |             ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
printer.cpp:44:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for (int i = 0; i < Str.size(); i++)
      |                         ~~^~~~~~~~~~~~
printer.cpp:50:35: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |                 if (Str[i].size() == level)
      |                     ~~~~~~~~~~~~~~^~~~~~~~
printer.cpp:62:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |             for (int j = 0; j < Last.length() - sim; j++)
      |                             ~~^~~~~~~~~~~~~~~~~~~~~
printer.cpp:64:33: 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 (int j = sim; j < Str[i].length(); j++)
      |                               ~~^~~~~~~~~~~~~~~~~
printer.cpp:73:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for (int i = 0; i < Finishes.size(); i++)
      |                         ~~^~~~~~~~~~~~~~~~~
printer.cpp:77:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |             for (int j = 0; j < Last.length() - sim; j++)
      |                             ~~^~~~~~~~~~~~~~~~~~~~~
printer.cpp:79:33: 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 j = sim; j < Finishes[i].length(); j++)
      |                               ~~^~~~~~~~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:108:32: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  108 |         if (To_Print[i].size() > MaxSize)
      |             ~~~~~~~~~~~~~~~~~~~^~~~~~~~~
printer.cpp:123:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |         for (int j = 0; j < Last.length()- sim; j++)
      |                         ~~^~~~~~~~~~~~~~~~~~~~
printer.cpp:125:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |         for (int j = sim; j < To_Print[i].length(); j++)
      |                           ~~^~~~~~~~~~~~~~~~~~~~~~
printer.cpp:133:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |         for (int i = 0; i < Last.size(); i++)
      |                         ~~^~~~~~~~~~~~~
printer.cpp:144:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  144 |     for (int i = 0; i < Commands.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~~~
printer.cpp:138:9: warning: 'FinalLetter' may be used uninitialized in this function [-Wmaybe-uninitialized]
  138 |         if (To_Print[i][0] == FinalLetter)
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...