#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,ssse3,sse4.1,sse4.2,avx,avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(x) begin(x), end(x)
#define x first
#define y second
typedef long long ll;
typedef long double ld;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using normal_queue = priority_queue<T, vector<T>, greater<T>>;
vector<string> strs;
vector<pair<string, int>> data_;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
strs.push_back(s);
}
sort(all(strs));
for (int i = 0; i < n; ) {
int st = i;
while (i < n && strs[i] == strs[st])
++i;
data_.push_back({strs[st], i - st});
}
int64_t ans = 0;
for (auto g : data_) {
string s = g.x;
int sz = (int) s.size();
set<string> ss;
for (int j = 0; j < sz; ++j)
for (int h = 1; h <= sz - j; ++h)
ss.insert(s.substr(j, h));
for (string t : ss) {
auto q = lower_bound(all(data_), pair<string, int>{t, -1});
if (q != data_.end() && q->x == t)
ans += q->y * g.y;
}
}
cout << ans - n << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
14 ms |
512 KB |
Output is correct |
6 |
Correct |
20 ms |
512 KB |
Output is correct |
7 |
Correct |
22 ms |
512 KB |
Output is correct |
8 |
Correct |
22 ms |
640 KB |
Output is correct |
9 |
Correct |
85 ms |
1276 KB |
Output is correct |
10 |
Correct |
103 ms |
1276 KB |
Output is correct |
11 |
Correct |
138 ms |
1788 KB |
Output is correct |
12 |
Correct |
201 ms |
1788 KB |
Output is correct |
13 |
Correct |
221 ms |
2168 KB |
Output is correct |
14 |
Correct |
227 ms |
3064 KB |
Output is correct |
15 |
Correct |
212 ms |
2168 KB |
Output is correct |
16 |
Correct |
36 ms |
1532 KB |
Output is correct |
17 |
Correct |
9 ms |
1532 KB |
Output is correct |
18 |
Correct |
10 ms |
1532 KB |
Output is correct |
19 |
Correct |
169 ms |
2040 KB |
Output is correct |
20 |
Correct |
36 ms |
1532 KB |
Output is correct |