Submission #966643

#TimeUsernameProblemLanguageResultExecution timeMemory
966643vjudge1Type Printer (IOI08_printer)C++17
100 / 100
93 ms4692 KiB
#include <bits/stdc++.h> using namespace std; int n, pr1, pr2, pr, mx; string arr[25010]; string l; int pref(string s1, string s2) { int i; for(i=0; i<min(s1.size(), s2.size()); i++) if(s1[i] != s2[i]) return i; return i; } bool cmp(string s1, string s2) { pr1 = pref(s1, l); pr2 = pref(s2, l); if(pr1 == pr2) return s1 < s2; return pr1 < pr2; } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for(int i=1; i<=n; i++) { cin >> arr[i]; if(arr[i].size() > l.size()) l = arr[i]; } sort(arr+1, arr+n+1, cmp); for(int i=1; i<=n; i++) { pr = pref(arr[i-1], arr[i]); mx += arr[i-1].size() + arr[i].size() - 2*pr; } cout << mx + n << "\n"; for(int i=1; i<=n; i++) { pr = pref(arr[i-1], arr[i]); for(int j=arr[i-1].size(); j>pr; j--) cout << "-\n"; for(int j=pr; j<arr[i].size(); j++) cout << arr[i][j] << "\n"; cout << "P\n"; } }

Compilation message (stderr)

printer.cpp: In function 'int pref(std::string, std::string)':
printer.cpp:11:15: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   11 |     for(i=0; i<min(s1.size(), s2.size()); i++) if(s1[i] != s2[i]) return i;
      |              ~^~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:38:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for(int j=pr; j<arr[i].size(); j++) cout << arr[i][j] << "\n";
      |                       ~^~~~~~~~~~~~~~
#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...