Submission #1020067

#TimeUsernameProblemLanguageResultExecution timeMemory
1020067TobType Printer (IOI08_printer)C++14
100 / 100
40 ms7692 KiB
#include <bits/stdc++.h> #define F first #define S second #define all(x) x.begin(), x.end() #define pb push_back #define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) using namespace std; typedef long long ll; typedef pair <ll, ll> pii; const int N = 25007; int n, p; string s[N], s2[N]; bool cmp(int x, int y) { int i = 0; for (i = 0; i < min((int)s2[x].size(), (int)s2[y].size()); i++) if (s2[x][i] != s2[y][i]) break; if (i != s2[x].size() && i != s2[y].size()) return (s2[x][i] < s2[y][i]); if (s2[x].size() == s2[y].size()) return (x < y); return (s2[x].size() < s2[y].size()); } int main () { FIO; cin >> n; int mx = 0; for (int i = 0; i < n; i++) { cin >> s[i]; if (s[i].size() > mx) { mx = s[i].size(); p = i; } s2[i] = s[i]; } vector <int> v; for (int i = 0; i < n; i++) if (i != p) { v.pb(i); for (int j = 0; j < mx && j < s[i].size() && s[i][j] == s[p][j]; j++) s2[i][j] = 'z'+1; } sort(all(v), cmp); v.pb(p); int le = 0; string res; for (int i = 0; i < n-1; i++) { int x = v[i], y = v[i+1]; while (le < s[x].size()) res += s[x][le++]; res += 'P'; int j; for (j = 0; j < le && j < s[y].size() && s[x][j] == s[y][j]; j++); while (le > j) {res += '-'; le--;} } while (le < s[p].size()) res += s[p][le++]; res += 'P'; cout << res.size() << "\n"; for (auto x : res) cout << x << "\n"; return 0; }

Compilation message (stderr)

printer.cpp: In function 'bool cmp(int, int)':
printer.cpp:22:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  if (i != s2[x].size() && i != s2[y].size()) return (s2[x][i] < s2[y][i]);
      |      ~~^~~~~~~~~~~~~~~
printer.cpp:22:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  if (i != s2[x].size() && i != s2[y].size()) return (s2[x][i] < s2[y][i]);
      |                           ~~^~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:33:19: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |   if (s[i].size() > mx) {
      |       ~~~~~~~~~~~~^~~~
printer.cpp:42:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for (int j = 0; j < mx && j < s[i].size() && s[i][j] == s[p][j]; j++) s2[i][j] = 'z'+1;
      |                             ~~^~~~~~~~~~~~~
printer.cpp:50:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   while (le < s[x].size()) res += s[x][le++];
      |          ~~~^~~~~~~~~~~~~
printer.cpp:53:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for (j = 0; j < le && j < s[y].size() && s[x][j] == s[y][j]; j++);
      |                         ~~^~~~~~~~~~~~~
printer.cpp:56:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  while (le < s[p].size()) res += s[p][le++];
      |         ~~~^~~~~~~~~~~~~
#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...