#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++){
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: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:28:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int len=1;len<=s[i].length();len++){
~~~^~~~~~~~~~~~~~~
lozinke.cpp:29: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 |
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 |
1152 KB |
Output is correct |
5 |
Correct |
22 ms |
1792 KB |
Output is correct |
6 |
Correct |
35 ms |
1664 KB |
Output is correct |
7 |
Correct |
46 ms |
3200 KB |
Output is correct |
8 |
Correct |
76 ms |
4728 KB |
Output is correct |
9 |
Correct |
187 ms |
4572 KB |
Output is correct |
10 |
Correct |
444 ms |
14712 KB |
Output is correct |
11 |
Correct |
393 ms |
7928 KB |
Output is correct |
12 |
Execution timed out |
1060 ms |
32632 KB |
Time limit exceeded |
13 |
Correct |
586 ms |
4464 KB |
Output is correct |
14 |
Correct |
698 ms |
28964 KB |
Output is correct |
15 |
Execution timed out |
1069 ms |
31932 KB |
Time limit exceeded |
16 |
Correct |
592 ms |
1600 KB |
Output is correct |
17 |
Correct |
121 ms |
896 KB |
Output is correct |
18 |
Correct |
95 ms |
1016 KB |
Output is correct |
19 |
Correct |
727 ms |
16248 KB |
Output is correct |
20 |
Correct |
271 ms |
1264 KB |
Output is correct |