Submission #782832

#TimeUsernameProblemLanguageResultExecution timeMemory
782832canadavid1Type Printer (IOI08_printer)C++14
100 / 100
73 ms17084 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) begin(x),end(x) vector<string> words; int common_substring(string a,string b) { int i; for(i = 0;i < a.size() && i < b.size() && a[i]==b[i]; i++); return i; } void sort2(int start, int end, int off, string lw) { if (end - start < 2) return; vector<string> s[26]; string lone_word = ""; for(int i = start; i < end; i++) { if(words[i].size()==off) {lone_word = words[i];continue;} char a = words[i][off]; s[a-'a'].push_back(words[i]); } int c = start; if(lone_word.size()) words[c++] = lone_word; for(int i = 0; i < 26; i++) { if(i==lw[off]-'a') continue; int pc = c; for(auto && v : s[i]) words[c++] = v; sort2(pc,c,off+1,lw); } int i = lw[off]-'a'; int pc = c; for(auto && v : s[i]) words[c++] = v; sort2(pc,c,off+1,lw); } int main() { cin.tie(nullptr)->sync_with_stdio(false); int N; cin >> N; words.resize(N); for(int i = 0; i < N; i++) { cin >> words[i]; } string longest_word = ""; for(auto i : words) if (i.size() > longest_word.size()) longest_word = i; // sort lexicographically, but have the characters in the longest word be the last ones sort2(0,N,0,longest_word); string curr = ""; string ops = ""; for(auto i : words) { int l = common_substring(curr,i); while(curr.size()>l) { curr.pop_back(); ops.push_back('-'); } curr += i.substr(l); ops += i.substr(l); ops.push_back('P'); } cout << ops.size() << "\n"; for(auto i : ops) cout << i << "\n"; }

Compilation message (stderr)

printer.cpp: In function 'int common_substring(std::string, std::string)':
printer.cpp:10:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(i = 0;i < a.size() && i < b.size() && a[i]==b[i]; i++);
      |               ~~^~~~~~~~~~
printer.cpp:10:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(i = 0;i < a.size() && i < b.size() && a[i]==b[i]; i++);
      |                               ~~^~~~~~~~~~
printer.cpp: In function 'void sort2(int, int, int, std::string)':
printer.cpp:22:27: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |         if(words[i].size()==off) {lone_word = words[i];continue;}
      |            ~~~~~~~~~~~~~~~^~~~~
printer.cpp: In function 'int main()':
printer.cpp:60:26: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |         while(curr.size()>l)
      |               ~~~~~~~~~~~^~
#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...