Submission #532941

#TimeUsernameProblemLanguageResultExecution timeMemory
532941prvocisloType Printer (IOI08_printer)C++17
100 / 100
61 ms5576 KiB
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <vector> typedef long long ll; using namespace std; int overlap(const string& a, const string& b) { for (int i = 0; i < a.size() && i < b.size(); i++) if (a[i] != b[i]) return i; return min(a.size(), b.size()); } string s; bool cmp(const string& a, const string& b) { int sa = overlap(s, a), sb = overlap(s, b); if (sa == sb) return a < b; return sa > sb; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<string> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; if (v[i].size() > v[0].size()) swap(v[0], v[i]); } s = v[0]; sort(v.begin() + 1, v.end(), cmp); reverse(v.begin(), v.end()); string pr; string ans; for (int i = 0; i < n; i++) { int pf = (i == 0 ? 0 : overlap(v[i - 1], v[i])); while (pr.size() > pf) { pr.pop_back(); ans.push_back('-'); } for (int j = pf; j < v[i].size(); j++) { pr.push_back(v[i][j]); ans.push_back(v[i][j]); } ans.push_back('P'); } cout << ans.size() << "\n"; for (char i : ans) cout << i << "\n"; return 0; }

Compilation message (stderr)

printer.cpp: In function 'int overlap(const string&, const string&)':
printer.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i = 0; i < a.size() && i < b.size(); i++) if (a[i] != b[i]) return i;
      |                     ~~^~~~~~~~~~
printer.cpp:20:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i = 0; i < a.size() && i < b.size(); i++) if (a[i] != b[i]) return i;
      |                                     ~~^~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:50:26: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |         while (pr.size() > pf)
      |                ~~~~~~~~~~^~~~
printer.cpp:55:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for (int j = pf; j < v[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...