#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
vector<pair<long long, string> > inp;
vector<long long> adj[20005];
long long vs[20005];
signed main(){
long long n;
cin >> n;
for(int i=0;i<n;i++){
string s;
cin >> s;
inp.push_back({s.size(),s});
}
long long ans=0;
sort(inp.begin(),inp.end());
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
if(inp[i].fi==inp[j].fi){
if(inp[i].se==inp[j].se){
for(auto t: adj[j]){
adj[j].push_back(t);
vs[t]=i;
}
adj[i].push_back(j);
//cout << inp[i].se<< " " << inp[j].se<<endl;
ans+=2;
}
}
else{
if(vs[j]==i){
ans++;
continue;
}
string a=inp[i].se;
string b=inp[j].se;
//cout << a << " " << b<< " " <<inp[i].fi-inp[j].fi+1<< " "<< ans<<" ";
for(int k=0;k<inp[i].fi-inp[j].fi+1;k++){
if(a[k]==b[0]){
long long test=0;
for(int l=0;l<inp[j].fi;l++){
if(a[k+l]!=b[l]){
test=1;
break;
}
}
if(test==0){
for(auto t: adj[j]){
adj[j].push_back(t);
vs[t]=i;
}
adj[i].push_back(j);
ans++;
break;
}
}
}
//cout << ans <<endl;
}
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
1408 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Runtime error |
3 ms |
1536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Runtime error |
4 ms |
1408 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Runtime error |
4 ms |
1536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Runtime error |
4 ms |
1664 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
5 ms |
1664 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
4 ms |
1664 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Correct |
45 ms |
1024 KB |
Output is correct |
9 |
Runtime error |
10 ms |
2424 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Runtime error |
11 ms |
2552 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Runtime error |
12 ms |
2808 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Runtime error |
23 ms |
2936 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Runtime error |
18 ms |
3180 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Runtime error |
16 ms |
3188 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Runtime error |
20 ms |
3304 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
16 |
Runtime error |
19 ms |
3188 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
17 |
Runtime error |
16 ms |
3188 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
18 |
Runtime error |
16 ms |
3188 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Runtime error |
19 ms |
3180 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
20 |
Runtime error |
16 ms |
3188 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |