# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
782798 | canadavid1 | Type Printer (IOI08_printer) | C++14 | 1078 ms | 2536 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)
using i32 = int32_t;
using i64 = int64_t;
int common_substring(string a,string b)
{
if(a.size() < b.size()) swap(a,b);
for(int i = b.size()-1;i >= 0; i--)
{
if(a.substr(0,i)==b.substr(0,i)) return i;
}
return 0;
}
int main()
{
cin.tie(nullptr)->sync_with_stdio(false);
i32 N;
cin >> N;
vector<string> words(N);
for(int i = 0; i < N; i++)
{
cin >> words[i];
}
sort(all(words));
string min_ops = "";
do
{
string curr = "";
string ops = "";
for(auto i : words)
{
i32 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');
}
if(min_ops.size()==0||ops.size() < min_ops.size()) min_ops = ops;
} while(next_permutation(all(words)));
cout << min_ops.size() << "\n";
for(auto i : min_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... |