#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(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
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++){
string tmp=s[i].substr(j,len);
if(check[tmp]==0){
ans=ans+cnt1[tmp];
check[tmp]=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++){
string tmp=s[i].substr(j,len);
if(check[tmp]==0){
ans=ans+cnt2[tmp];
check[tmp]=1;
}
}
}
cnt2[s[i]]++;
}
cout<<ans;
}
Compilation message
lozinke.cpp: In function 'int main()':
lozinke.cpp:16:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int len=1;len<=s[i].length();len++){
~~~^~~~~~~~~~~~~~~
lozinke.cpp:17:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j+len-1<s[i].length();j++){
~~~~~~~^~~~~~~~~~~~~~
lozinke.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int len=1;len<=s[i].length();len++){
~~~^~~~~~~~~~~~~~~
lozinke.cpp:30: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 |
22 ms |
1792 KB |
Output is correct |
6 |
Correct |
36 ms |
1716 KB |
Output is correct |
7 |
Correct |
46 ms |
3192 KB |
Output is correct |
8 |
Correct |
82 ms |
4856 KB |
Output is correct |
9 |
Correct |
193 ms |
4572 KB |
Output is correct |
10 |
Correct |
444 ms |
14712 KB |
Output is correct |
11 |
Correct |
322 ms |
7928 KB |
Output is correct |
12 |
Execution timed out |
1066 ms |
32504 KB |
Time limit exceeded |
13 |
Correct |
587 ms |
4416 KB |
Output is correct |
14 |
Correct |
740 ms |
29020 KB |
Output is correct |
15 |
Execution timed out |
1080 ms |
31708 KB |
Time limit exceeded |
16 |
Correct |
581 ms |
1248 KB |
Output is correct |
17 |
Correct |
116 ms |
1144 KB |
Output is correct |
18 |
Correct |
83 ms |
1024 KB |
Output is correct |
19 |
Correct |
724 ms |
16348 KB |
Output is correct |
20 |
Correct |
264 ms |
1272 KB |
Output is correct |