#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>>;
multiset<string> 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;
data_.insert(s);
}
int64_t ans = 0;
for (string s : data_) {
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)
ans += data_.count(t);
}
cout << ans - n << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
16 ms |
384 KB |
Output is correct |
6 |
Correct |
21 ms |
512 KB |
Output is correct |
7 |
Correct |
26 ms |
512 KB |
Output is correct |
8 |
Correct |
30 ms |
512 KB |
Output is correct |
9 |
Correct |
234 ms |
1248 KB |
Output is correct |
10 |
Correct |
160 ms |
1152 KB |
Output is correct |
11 |
Correct |
424 ms |
1664 KB |
Output is correct |
12 |
Correct |
304 ms |
1664 KB |
Output is correct |
13 |
Correct |
327 ms |
2128 KB |
Output is correct |
14 |
Correct |
369 ms |
2200 KB |
Output is correct |
15 |
Correct |
325 ms |
2168 KB |
Output is correct |
16 |
Correct |
325 ms |
2048 KB |
Output is correct |
17 |
Execution timed out |
1055 ms |
2048 KB |
Time limit exceeded |
18 |
Execution timed out |
1085 ms |
2048 KB |
Time limit exceeded |
19 |
Correct |
280 ms |
2048 KB |
Output is correct |
20 |
Correct |
681 ms |
2128 KB |
Output is correct |