#include<bits/stdc++.h>
using namespace std;
bool cmp(string a,string b){
return a.length() < b.length();
}
long long n,ans;
string s[20005];
map<string,int> cnt1,cnt2;
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>s[i];
sort(s+1,s+1+n,cmp);
for(int i=1;i<=n;i++){
map<string,bool> check;
for(int len=1;len<=s[i].length();len++){
for(int j=0;j+len-1<s[i].length();j++){
if(check[s[i].substr(j,len)]==0){
ans=ans+cnt1[s[i].substr(j,len)];
check[s[i].substr(j,len)]=1;
}
}
}
cnt1[s[i]]++;
}
for(int i=n;i>=1;i--){
map<string,bool> check;
for(int len=1;len<=s[i].length();len++){
for(int j=0;j+len-1<s[i].length();j++){
if(check[s[i].substr(j,len)]==0){
ans=ans+cnt2[s[i].substr(j,len)];
check[s[i].substr(j,len)]=1;
}
}
}
cnt2[s[i]]++;
}
cout<<ans;
}
Compilation message
lozinke.cpp: In function 'int main()':
lozinke.cpp:15:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int len=1;len<=s[i].length();len++){
~~~^~~~~~~~~~~~~~~
lozinke.cpp:16:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j+len-1<s[i].length();j++){
~~~~~~~^~~~~~~~~~~~~~
lozinke.cpp:27:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int len=1;len<=s[i].length();len++){
~~~^~~~~~~~~~~~~~~
lozinke.cpp:28:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j+len-1<s[i].length();j++){
~~~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1024 KB |
Output is correct |
2 |
Correct |
3 ms |
1024 KB |
Output is correct |
3 |
Correct |
4 ms |
1024 KB |
Output is correct |
4 |
Correct |
5 ms |
1024 KB |
Output is correct |
5 |
Correct |
23 ms |
1784 KB |
Output is correct |
6 |
Correct |
35 ms |
1656 KB |
Output is correct |
7 |
Correct |
47 ms |
3068 KB |
Output is correct |
8 |
Correct |
77 ms |
4856 KB |
Output is correct |
9 |
Correct |
191 ms |
4672 KB |
Output is correct |
10 |
Correct |
435 ms |
14740 KB |
Output is correct |
11 |
Correct |
369 ms |
7908 KB |
Output is correct |
12 |
Execution timed out |
1018 ms |
32628 KB |
Time limit exceeded |
13 |
Correct |
629 ms |
4600 KB |
Output is correct |
14 |
Correct |
691 ms |
29048 KB |
Output is correct |
15 |
Execution timed out |
1067 ms |
29432 KB |
Time limit exceeded |
16 |
Correct |
658 ms |
1348 KB |
Output is correct |
17 |
Correct |
132 ms |
1024 KB |
Output is correct |
18 |
Correct |
95 ms |
1116 KB |
Output is correct |
19 |
Correct |
885 ms |
16220 KB |
Output is correct |
20 |
Correct |
418 ms |
1288 KB |
Output is correct |