Submission #927941

#TimeUsernameProblemLanguageResultExecution timeMemory
927941TAhmed33Type Printer (IOI08_printer)C++98
100 / 100
66 ms5484 KiB
#include <bits/stdc++.h> using namespace std; vector <string> arr; string ans; int main () { int n; cin >> n; arr.resize(n); string p; for (auto &i : arr) { cin >> i; if (i.length() > p.length()) { p = i; } } sort(arr.begin(), arr.end(), [p] (string &a, string &b) { int cnt1 = 0, cnt2 = 0; for (int i = 0; i < (int)a.length() && i < (int)p.length(); i++) { if (a[i] != p[i]) break; cnt1++; } for (int i = 0; i < (int)b.length() && i < (int)p.length(); i++) { if (b[i] != p[i]) break; cnt2++; } if (cnt1 == cnt2) return a < b; return cnt1 < cnt2; }); ans = arr[0]; ans += 'P'; for (int i = 1; i < n; i++) { if (arr[i - 1].length() > arr[i].length()) { int x = arr[i - 1].length() - arr[i].length(); for (int j = 0; j < x; j++) { arr[i - 1].pop_back(); ans += '-'; } string dd = arr[i]; while (!arr[i - 1].empty() && arr[i - 1] != arr[i]) { arr[i - 1].pop_back(); arr[i].pop_back(); ans += '-'; } for (int j = (int)arr[i - 1].length(); j < dd.length(); j++) { ans += dd[j]; } ans += 'P'; arr[i] = dd; continue; } if (arr[i - 1].length() == arr[i].length()) { string dd = arr[i]; while (!arr[i - 1].empty() && arr[i - 1] != arr[i]) { arr[i - 1].pop_back(); arr[i].pop_back(); ans += '-'; } for (int j = (int)arr[i - 1].length(); j < dd.length(); j++) { ans += dd[j]; } ans += 'P'; arr[i] = dd; continue; } string dd = arr[i]; while (arr[i].length() > arr[i - 1].length()) { arr[i].pop_back(); } while (!arr[i - 1].empty() && arr[i - 1] != arr[i]) { arr[i - 1].pop_back(); arr[i].pop_back(); ans += '-'; } for (int j = (int)arr[i - 1].length(); j < dd.length(); j++) { ans += dd[j]; } ans += 'P'; arr[i] = dd; continue; } cout << ans.length() << '\n'; for (auto i : ans) cout << i << '\n'; }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:44:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |    for (int j = (int)arr[i - 1].length(); j < dd.length(); j++) {
      |                                           ~~^~~~~~~~~~~~~
printer.cpp:58:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |    for (int j = (int)arr[i - 1].length(); j < dd.length(); j++) {
      |                                           ~~^~~~~~~~~~~~~
printer.cpp:74:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   for (int j = (int)arr[i - 1].length(); j < dd.length(); 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...