Submission #966655

#TimeUsernameProblemLanguageResultExecution timeMemory
966655vjudge1Type Printer (IOI08_printer)C++17
100 / 100
88 ms4688 KiB
#include <bits/stdc++.h> using namespace std; int n, dif, ans; string s[25010]; string l; int diff(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) { int diff1 = diff(s1, l); int diff2 = diff(s2, l); if(diff1 == diff2) return s1 < s2; return diff1 < diff2; } int main() { cin.tie(nullptr)->sync_with_stdio(false); cin >> n; for(int i=1; i<=n; i++) { cin >> s[i]; if(s[i].size() > l.size()) l = s[i]; } sort(s+1, s+n+1, cmp); for(int i=1; i<=n; i++) { dif = diff(s[i-1], s[i]); ans += s[i-1].size() + s[i].size() - 2*dif; } cout << ans + n << "\n"; for(int i=1; i<=n; i++) { dif = diff(s[i-1], s[i]); for(int j=s[i-1].size(); j>dif; j--) cout << "-\n"; for(int j=dif; j<s[i].size(); j++) cout << s[i][j] << "\n"; cout << "P\n"; } }

Compilation message (stderr)

printer.cpp: In function 'int diff(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:25: 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=dif; j<s[i].size(); j++) cout << s[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...