//#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;
map<string,bool> mb;
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;
for (int i=0;i<s[x].size();i++) {
if (s[x][i]>s[y][i]) return false;
if (s[x][i]<s[y][i]) 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 'bool ss(int, int)':
lozinke.cpp:16:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<s[x].size();i++) {
~^~~~~~~~~~~~
lozinke.cpp: In function 'int main()':
lozinke.cpp:51:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=0;j<s[i].size();j++) {
~^~~~~~~~~~~~
lozinke.cpp:53:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int l=j;l<s[i].size();l++) {
~^~~~~~~~~~~~
lozinke.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1024 KB |
Output is correct |
2 |
Correct |
3 ms |
896 KB |
Output is correct |
3 |
Correct |
3 ms |
1024 KB |
Output is correct |
4 |
Correct |
4 ms |
1024 KB |
Output is correct |
5 |
Correct |
13 ms |
1280 KB |
Output is correct |
6 |
Correct |
19 ms |
1288 KB |
Output is correct |
7 |
Correct |
26 ms |
2048 KB |
Output is correct |
8 |
Correct |
39 ms |
2936 KB |
Output is correct |
9 |
Correct |
97 ms |
2808 KB |
Output is correct |
10 |
Correct |
245 ms |
7800 KB |
Output is correct |
11 |
Correct |
164 ms |
4472 KB |
Output is correct |
12 |
Correct |
518 ms |
16636 KB |
Output is correct |
13 |
Correct |
229 ms |
2668 KB |
Output is correct |
14 |
Correct |
314 ms |
14840 KB |
Output is correct |
15 |
Correct |
454 ms |
16376 KB |
Output is correct |
16 |
Correct |
221 ms |
1144 KB |
Output is correct |
17 |
Execution timed out |
1068 ms |
1308 KB |
Time limit exceeded |
18 |
Execution timed out |
1073 ms |
1628 KB |
Time limit exceeded |
19 |
Correct |
292 ms |
8532 KB |
Output is correct |
20 |
Correct |
151 ms |
1144 KB |
Output is correct |