Submission #800263

#TimeUsernameProblemLanguageResultExecution timeMemory
800263LiudasType Printer (IOI08_printer)C++17
40 / 100
776 ms7564 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N; cin >> N; vector<string> arr(N); for(string &i : arr)cin >> i; sort(arr.begin(), arr.end()); arr.push_back(""); vector<char> brr; vector<string> ans; string temp = "P"; vector<char> a2, a3; for(string i : arr){ int k = 0; while(k < brr.size() && k < i.size() && brr[k] == i[k]){ k++; } int t = brr.size(); for(int j = k; j < t; j ++){ temp += "-"; brr.pop_back(); } if(k == 0){ ans.push_back(temp); temp = ""; } for(int j = k; j < i.size(); j ++){ brr.push_back(i[j]); temp += i.substr(j, 1); } temp += "P"; } ans.erase(ans.begin()); map<string, int> len; for(string i : ans){ int t = count(i.begin(), i.begin() + i.rfind('P'), '-'); int tt = count(i.begin(), i.end(), 'P'); int ttt = i.rfind('P') - 2 * t - tt + 1; len[i] = ttt; } sort(ans.begin(), ans.end(), [&](string a, string b){return len[a] < len[b];}); for(string i : ans){ for(char j : i){ a2.push_back(j); } } while(a2.back() =='-')a2.pop_back(); temp = "P"; ans.clear(); brr.clear(); sort(arr.begin(), arr.end(),[](string a, string b){return a > b;}); for(string i : arr){ int k = 0; while(k < brr.size() && k < i.size() && brr[k] == i[k]){ k++; } int t = brr.size(); for(int j = k; j < t; j ++){ temp += "-"; brr.pop_back(); } if(k == 0){ ans.push_back(temp); temp = ""; } for(int j = k; j < i.size(); j ++){ brr.push_back(i[j]); temp += i.substr(j, 1); } temp += "P"; } ans.erase(ans.begin()); len.clear(); for(string i : ans){ int t = count(i.begin(), i.begin() + i.rfind('P'), '-'); int tt = count(i.begin(), i.end(), 'P'); int ttt = i.rfind('P') - 2 * t - tt + 1; len[i] = ttt; } sort(ans.begin(), ans.end(), [&](string a, string b){return len[a] < len[b];}); for(string i : ans){ for(char j : i){ a3.push_back(j); } } while(a3.back() =='-')a3.pop_back(); if(a2.size() > a3.size())swap(a2,a3); cout << a2.size() << endl; for(char i : a2){ cout << i << endl; } return 0; }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:20:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         while(k < brr.size() && k < i.size() && brr[k] == i[k]){
      |               ~~^~~~~~~~~~~~
printer.cpp:20:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         while(k < brr.size() && k < i.size() && brr[k] == i[k]){
      |                                 ~~^~~~~~~~~~
printer.cpp:32:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(int j = k; j < i.size(); j ++){
      |                        ~~^~~~~~~~~~
printer.cpp:59:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         while(k < brr.size() && k < i.size() && brr[k] == i[k]){
      |               ~~^~~~~~~~~~~~
printer.cpp:59:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         while(k < brr.size() && k < i.size() && brr[k] == i[k]){
      |                                 ~~^~~~~~~~~~
printer.cpp:71:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for(int j = k; j < i.size(); j ++){
      |                        ~~^~~~~~~~~~
#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...