#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];
unordered_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++){
unordered_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--){
unordered_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++){
~~~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1024 KB |
Output is correct |
2 |
Correct |
3 ms |
1024 KB |
Output is correct |
3 |
Correct |
3 ms |
1024 KB |
Output is correct |
4 |
Correct |
4 ms |
1152 KB |
Output is correct |
5 |
Correct |
14 ms |
1792 KB |
Output is correct |
6 |
Correct |
24 ms |
1664 KB |
Output is correct |
7 |
Correct |
27 ms |
3328 KB |
Output is correct |
8 |
Correct |
43 ms |
4728 KB |
Output is correct |
9 |
Correct |
104 ms |
4472 KB |
Output is correct |
10 |
Correct |
246 ms |
14212 KB |
Output is correct |
11 |
Correct |
178 ms |
7656 KB |
Output is correct |
12 |
Correct |
558 ms |
30396 KB |
Output is correct |
13 |
Correct |
298 ms |
4444 KB |
Output is correct |
14 |
Correct |
397 ms |
27576 KB |
Output is correct |
15 |
Correct |
632 ms |
29872 KB |
Output is correct |
16 |
Correct |
299 ms |
1424 KB |
Output is correct |
17 |
Correct |
138 ms |
896 KB |
Output is correct |
18 |
Correct |
103 ms |
896 KB |
Output is correct |
19 |
Correct |
379 ms |
15336 KB |
Output is correct |
20 |
Correct |
165 ms |
1400 KB |
Output is correct |