# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
532941 | prvocislo | Type Printer (IOI08_printer) | C++17 | 61 ms | 5576 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |