#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
unordered_map<string, int> st, subst;
for(int i = 0; i < n; i++) {
string s;
cin >> s;
st[s]++;
int n = s.length();
unordered_map<string, bool> stemp;
for(int i = 0; i < n; i++) {
string k = "";
for(int j = i; j < n; j++) {
k += s[j];
stemp[k] = true;
}
}
for(auto &x: stemp) {
subst[x.first]+=x.second;
}
}
int64_t ans = 0;
for(auto &s: st) {
ans += 1ll * s.second * (subst[s.first] - 1);
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
6 ms |
748 KB |
Output is correct |
6 |
Correct |
10 ms |
748 KB |
Output is correct |
7 |
Correct |
14 ms |
1388 KB |
Output is correct |
8 |
Correct |
20 ms |
2284 KB |
Output is correct |
9 |
Correct |
53 ms |
2540 KB |
Output is correct |
10 |
Correct |
121 ms |
7312 KB |
Output is correct |
11 |
Correct |
95 ms |
4364 KB |
Output is correct |
12 |
Correct |
292 ms |
15984 KB |
Output is correct |
13 |
Correct |
154 ms |
3052 KB |
Output is correct |
14 |
Correct |
223 ms |
15028 KB |
Output is correct |
15 |
Correct |
312 ms |
15796 KB |
Output is correct |
16 |
Correct |
156 ms |
876 KB |
Output is correct |
17 |
Correct |
74 ms |
492 KB |
Output is correct |
18 |
Correct |
55 ms |
492 KB |
Output is correct |
19 |
Correct |
189 ms |
8592 KB |
Output is correct |
20 |
Correct |
89 ms |
748 KB |
Output is correct |