#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool minn(T &A,T B){return A > B ? (A = B,1) : 0;}
template <class T> inline bool maxx(T &A,T B){return A < B ? (A = B,1) : 0;}
#define pb push_back
#define endl '\n'
#define SZ(x) (int)((x).size())
#define dem(x) __builtin_popcount(x)
#define fi first
#define se second
//#define int long long
typedef pair<int,int> ii;
typedef long long ll;
const ll mod = 1e9 + 7; //998244353
vector<int> a[10000005];
char c[10000005], ans[10000005];
string s;
int d[10000005], n, best[10000005], cnt, t;
void add(int id,string s,int it)
{
if(it == SZ(s))return;
bool ck = 1;
for(int i : a[id])if(c[i] == s[it]){
ck = 0;
add(i, s, it + 1);
if(maxx(d[id], d[i] + 1))best[id] = i;
break;
}
if(ck){
cnt++;
a[id].pb(cnt);
c[cnt] = s[it];
add(cnt, s, it + 1);
if(maxx(d[id], d[a[id].back()] + 1))best[id] = a[id].back();
}
}
void DFS(int id)
{
ans[++t] = c[id];
if(SZ(a[id]) == 0){
cnt++;
ans[++t] = 'P';
if(cnt == n){
cout << t - 1 << endl;
for(int i = 2;i < t;++i)cout << ans[i] << endl;
cout << ans[t];
exit(0);
}
ans[++t] = '-';
return;
}
for(int i : a[id])if(i != best[id])DFS(i);
DFS(best[id]);
ans[++t] = '-';
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
// freopen("c.inp","r",stdin);
cin >> n;
for(int i = 0;i < n;++i){
cin >> s;
add(0, s, 0);
}
cnt = 0;
DFS(0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
150 ms |
235160 KB |
Output is correct |
2 |
Correct |
148 ms |
235076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
145 ms |
235076 KB |
Output is correct |
2 |
Correct |
146 ms |
235060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
143 ms |
235128 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
146 ms |
235136 KB |
Output is correct |
2 |
Incorrect |
137 ms |
235084 KB |
Unexpected end of file - int32 expected |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
153 ms |
235144 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
143 ms |
235392 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
152 ms |
236020 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
153 ms |
237596 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
177 ms |
241360 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
167 ms |
239684 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |