//#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define f_(i,a,b) for (int i=a;i>=b;i--)
//#define f(i,a,b) for (int i=a;i<=b;i++)
int n;
string s[20005];
long long dem=0;
unordered_map<string,bool> mb;
unordered_map<string,ll> m;
bool ss(int x,int y) {
if (s[x].size()>s[y].size()) return false;
if (s[x].size()<s[y].size()) return true;
return true;
}
void xot(int l,int r) {
if (l>=r) return ;
int pos;
pos=l;
string si;
for (int i=l;i<r;i++) {
if (ss(i,r)) {
si=s[i];
s[i]=s[pos];
s[pos]=si;
pos++;
}
}
si=s[r];
s[r]=s[pos];
s[pos]=si;
xot(l,pos-1);
xot(pos+1,r);
}
int main() {
// freopen("","r",stdin);
// freopen("","w",stdout);
scanf("%d", &n);
for (int i=1;i<=n;i++) {
cin>>s[i];
}
xot(1,n);
for (int i=1;i<=n;i++) {
mb.clear();
for (int j=0;j<s[i].size();j++) {
string si;
for (int l=j;l<s[i].size();l++) {
si=si+s[i][l];
if (!mb[si]) {
mb[si]=true;
dem+=m[si];
}
}
}
dem+=m[s[i]];
m[s[i]]++;
}
printf("%lld", dem);
return 0;
}
Compilation message
lozinke.cpp: In function 'int main()':
lozinke.cpp:47:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=0;j<s[i].size();j++) {
~^~~~~~~~~~~~
lozinke.cpp:49:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int l=j;l<s[i].size();l++) {
~^~~~~~~~~~~~
lozinke.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1024 KB |
Output is correct |
2 |
Correct |
5 ms |
896 KB |
Output is correct |
3 |
Correct |
4 ms |
1024 KB |
Output is correct |
4 |
Correct |
4 ms |
1024 KB |
Output is correct |
5 |
Correct |
10 ms |
1280 KB |
Output is correct |
6 |
Correct |
14 ms |
1280 KB |
Output is correct |
7 |
Correct |
19 ms |
2148 KB |
Output is correct |
8 |
Correct |
31 ms |
2808 KB |
Output is correct |
9 |
Correct |
147 ms |
2792 KB |
Output is correct |
10 |
Correct |
277 ms |
7560 KB |
Output is correct |
11 |
Correct |
285 ms |
4408 KB |
Output is correct |
12 |
Correct |
822 ms |
15672 KB |
Output is correct |
13 |
Correct |
897 ms |
3064 KB |
Output is correct |
14 |
Correct |
621 ms |
14240 KB |
Output is correct |
15 |
Correct |
988 ms |
15384 KB |
Output is correct |
16 |
Execution timed out |
1075 ms |
2304 KB |
Time limit exceeded |
17 |
Execution timed out |
1077 ms |
1400 KB |
Time limit exceeded |
18 |
Correct |
822 ms |
1528 KB |
Output is correct |
19 |
Correct |
624 ms |
8328 KB |
Output is correct |
20 |
Correct |
552 ms |
1560 KB |
Output is correct |