Submission #1026264

#TimeUsernameProblemLanguageResultExecution timeMemory
1026264ach00Type Printer (IOI08_printer)C++14
100 / 100
53 ms8168 KiB
#include <bits/stdc++.h> using namespace std; bool cmp(const string &s1, const string &s2) { return s1.size() < s2.size(); } int main() { int n; cin >> n; vector<string> words(n); vector<bool> printed(n, false); vector<char> cprint; int pc = 0; for(auto &a : words) cin >> a; sort(words.begin(), words.end(), cmp); string biggest_word = words[n-1]; vector<char> ans; vector<pair<int, string>> prefixsort; for(int i = 0; i < n-1; i++) { int cnt = 0; for(int j = 0; j < words[i].size(); j++) { if(words[i][j] == biggest_word[j]) cnt++; else break; } prefixsort.push_back({cnt, words[i]}); } prefixsort.push_back({biggest_word.size(), biggest_word}); sort(prefixsort.begin(), prefixsort.end()); for(int i = 0; i < n; i++) { string word = prefixsort[i].second; int cnt = 0; for(int j = 0; j < cprint.size(); j++) { if(cprint[j] == word[j]) cnt++; else break; } while(cprint.size() != cnt) { ans.push_back('-'); cprint.pop_back(); } for(int j = cnt; j < word.size(); j++) { cprint.push_back(word[j]); ans.push_back(word[j]); } ans.push_back('P'); } cout << ans.size() << '\n'; for(auto &s : ans) { cout << s << '\n'; } }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:21:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for(int j = 0; j < words[i].size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~~~
printer.cpp:32:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(int j = 0; j < cprint.size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~
printer.cpp:36:29: warning: comparison of integer expressions of different signedness: 'std::vector<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |         while(cprint.size() != cnt) {
      |               ~~~~~~~~~~~~~~^~~~~~
printer.cpp:40:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int j = cnt; j < word.size(); j++) {
      |                          ~~^~~~~~~~~~~~~
printer.cpp:13:9: warning: unused variable 'pc' [-Wunused-variable]
   13 |     int pc = 0;
      |         ^~
#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...