#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
#define sz(x) ll(x.size())
#define base 1000000
#define M ll(1e9+7)
#define N 100005
#define F first
#define S second
#define pb push_back
#define in insert
#define eb emplace_back
#define ed "\n"
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef short int si;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
map <string, int> mp;
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll ans =0 ;
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++)
{
set <string> se; se.clear();
for (int kl = 0; kl < sz(s[i]); kl++)
for (int kr = 0; kr < sz(s[i]) - kl; kr++)
{
string str = "";
for (int j = kl; j < sz(s[i]) - kr; j++) str += s[i][j];
if (se.find(str) == se.end()) {se.insert(str); mp[str]++;}
}
}
for (int i = 0; i < n; i++)
{
mp[s[i]]--;
ans += mp[s[i]];
mp[s[i]]++;
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
7 ms |
512 KB |
Output is correct |
5 |
Correct |
18 ms |
768 KB |
Output is correct |
6 |
Correct |
26 ms |
768 KB |
Output is correct |
7 |
Correct |
33 ms |
1408 KB |
Output is correct |
8 |
Correct |
48 ms |
2296 KB |
Output is correct |
9 |
Correct |
131 ms |
2424 KB |
Output is correct |
10 |
Correct |
252 ms |
7544 KB |
Output is correct |
11 |
Correct |
199 ms |
4216 KB |
Output is correct |
12 |
Correct |
569 ms |
16504 KB |
Output is correct |
13 |
Correct |
387 ms |
2680 KB |
Output is correct |
14 |
Correct |
393 ms |
14940 KB |
Output is correct |
15 |
Correct |
570 ms |
16376 KB |
Output is correct |
16 |
Correct |
419 ms |
1272 KB |
Output is correct |
17 |
Correct |
118 ms |
896 KB |
Output is correct |
18 |
Correct |
83 ms |
896 KB |
Output is correct |
19 |
Correct |
403 ms |
8568 KB |
Output is correct |
20 |
Correct |
203 ms |
1144 KB |
Output is correct |