# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1026291 | fv3 | Type Printer (IOI08_printer) | C++14 | 25 ms | 2296 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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1ll << 60ll;
vector<int> order(26);
bool compare(string a, string b)
{
for (int i = 0; i < min(a.size(), b.size()); i++)
{
if (order[a[i]-'a'] > order[b[i]-'a']) return true;
if (order[a[i]-'a'] < order[b[i]-'a']) return false;
}
return a.size() < b.size();
}
string printSolution(vector<string>&bestPerm)
{
string res = "";
string lastWord = "";
for (auto w : bestPerm)
{
int i = 0;
for (; i < min(lastWord.size(), w.size()); i++)
{
if (w[i] != lastWord[i])
break;
}
for (int j = 0; j < lastWord.size() - i; j++)
res += "-";
for (; i < w.size(); i++)
res += w[i];
res += "P";
lastWord = w;
}
return res;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
vector<string> words(N);
string longest = "";
for (int i = 0; i < N; i++)
{
cin >> words[i];
if (words[i].size() > longest.size())
longest = words[i];
}
int x = 1;
for (auto c : longest)
{
if (order[c-'a']) continue;
order[c-'a'] = x++;
}
for (int i = 0; i < 26; i++)
{
if (order[i] == 0)
order[i] = x++;
}
sort(words.begin(), words.end(), compare);
string res = printSolution(words);
cout << res.size() << '\n';
for (auto c : res)
{
cout << c << '\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... |