#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<string> v;
map<string, int> pass;
for(int i = 0; i < n; i++) {
string str;
cin >> str;
v.push_back(str);
pass[str]++;
}
int cnt = 0;
for(int s = 0; s < n; s++) {
string str = v[s];
int l = str.length();
set<string> st;
st.insert(str);
int curr = max(0, pass[str]-1);
for(int i = 0; i < l; i++) {
string sub;
for(int j = i; j < l; j++) {
sub += str[j];
if (st.count(sub)) continue;
st.insert(sub);
curr += pass[sub];
}
}
cnt += curr;
}
cout << cnt << "\n";
return 0;
}
//~ check for overflows
# |
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 |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
12 ms |
748 KB |
Output is correct |
6 |
Correct |
21 ms |
748 KB |
Output is correct |
7 |
Correct |
26 ms |
1516 KB |
Output is correct |
8 |
Correct |
44 ms |
2276 KB |
Output is correct |
9 |
Correct |
114 ms |
2524 KB |
Output is correct |
10 |
Correct |
233 ms |
7516 KB |
Output is correct |
11 |
Correct |
198 ms |
4568 KB |
Output is correct |
12 |
Correct |
531 ms |
16604 KB |
Output is correct |
13 |
Correct |
358 ms |
2900 KB |
Output is correct |
14 |
Correct |
365 ms |
15064 KB |
Output is correct |
15 |
Correct |
572 ms |
16472 KB |
Output is correct |
16 |
Correct |
360 ms |
1872 KB |
Output is correct |
17 |
Correct |
72 ms |
1772 KB |
Output is correct |
18 |
Correct |
53 ms |
1644 KB |
Output is correct |
19 |
Correct |
392 ms |
8840 KB |
Output is correct |
20 |
Correct |
175 ms |
1716 KB |
Output is correct |