# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
782832 | canadavid1 | Type Printer (IOI08_printer) | C++14 | 73 ms | 17084 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;
#define all(x) begin(x),end(x)
vector<string> words;
int common_substring(string a,string b)
{
int i;
for(i = 0;i < a.size() && i < b.size() && a[i]==b[i]; i++);
return i;
}
void sort2(int start, int end, int off, string lw)
{
if (end - start < 2) return;
vector<string> s[26];
string lone_word = "";
for(int i = start; i < end; i++)
{
if(words[i].size()==off) {lone_word = words[i];continue;}
char a = words[i][off];
s[a-'a'].push_back(words[i]);
}
int c = start;
if(lone_word.size()) words[c++] = lone_word;
for(int i = 0; i < 26; i++)
{
if(i==lw[off]-'a') continue;
int pc = c;
for(auto && v : s[i]) words[c++] = v;
sort2(pc,c,off+1,lw);
}
int i = lw[off]-'a';
int pc = c;
for(auto && v : s[i]) words[c++] = v;
sort2(pc,c,off+1,lw);
}
int main()
{
cin.tie(nullptr)->sync_with_stdio(false);
int N;
cin >> N;
words.resize(N);
for(int i = 0; i < N; i++)
{
cin >> words[i];
}
string longest_word = "";
for(auto i : words) if (i.size() > longest_word.size()) longest_word = i;
// sort lexicographically, but have the characters in the longest word be the last ones
sort2(0,N,0,longest_word);
string curr = "";
string ops = "";
for(auto i : words)
{
int l = common_substring(curr,i);
while(curr.size()>l)
{
curr.pop_back();
ops.push_back('-');
}
curr += i.substr(l);
ops += i.substr(l);
ops.push_back('P');
}
cout << ops.size() << "\n";
for(auto i : ops) cout << i << "\n";
}
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... |