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 <iostream>
#include <cstdlib>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <queue>
#include <math.h>
#include <stack>
#include <vector>
#include <string.h>
#include <random>
typedef long long ll;
const ll MOD = 1e9 + 7, INF = 1e18;
using namespace std;
int n, ptr, printed;
string ans;
struct Node
{
map <char, pair <int, int> > next;
bool st;
} a[1000000];
void add (string s)
{
int x = 0;
for (int i = 0; i < s.length (); i++)
{
if (a[x].next.find (s[i]) == a[x].next.end ())
{
a[x].next[s[i]] = make_pair (ptr + 1, (int) s.length () - i);
ptr++;
}
if (a[x].next[s[i]].second < (int) s.length () - i)
a[x].next[s[i]].second = (int) s.length () - i;
x = a[x].next[s[i]].first;
}
a[x].st = true;
}
void dfs (int x)
{
vector < pair <int, char> > v;
if (a[x].st)
{
ans += 'P';
printed++;
}
for (pair <char, pair <int, int> > it : a[x].next)
v.emplace_back (it.second.second, it.first);
sort (v.begin(), v.end());
for (auto to : v)
{
ans += char (to.second);
dfs (a[x].next[to.second].first);
}
if (printed < n) ans += '-';
}
int main ()
{
cin >> n;
for (int i = 0; i < n; i++)
{
string s;
cin >> s;
add (s);
}
dfs (0);
cout << ans.length () << endl;
for (auto a : ans)
printf ("%c\n", a);
}
Compilation message (stderr)
printer.cpp: In function 'void add(std::__cxx11::string)':
printer.cpp:36:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < s.length (); i++)
~~^~~~~~~~~~~~~
# | 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... |