#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
using namespace std;
map<string, int> ct;
void map_insert(string s)
{
if(ct.find(s) == ct.end()) ct[s] = 1;
else ct[s]++;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
vector<string> s(N);
for(int i = 0; i < N; i++)
{
cin >> s[i];
int k = int(s[i].size());
set<string> z;
for(int j = 0; j < k; j++)
for(int l = j; l < k; l++)
z.insert(s[i].substr(j, l-j+1));
for(string t: z)
map_insert(t);
}
int ans = 0;
for(int i = 0; i < N; i++)
{
// cerr << i << " : " << ct[s[i]] << '\n';
ans += ct[s[i]] - 1;
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
11 ms |
636 KB |
Output is correct |
6 |
Correct |
17 ms |
656 KB |
Output is correct |
7 |
Correct |
24 ms |
1416 KB |
Output is correct |
8 |
Correct |
40 ms |
2260 KB |
Output is correct |
9 |
Correct |
105 ms |
2360 KB |
Output is correct |
10 |
Correct |
234 ms |
7492 KB |
Output is correct |
11 |
Correct |
199 ms |
4244 KB |
Output is correct |
12 |
Correct |
476 ms |
16532 KB |
Output is correct |
13 |
Correct |
321 ms |
2796 KB |
Output is correct |
14 |
Correct |
336 ms |
14968 KB |
Output is correct |
15 |
Correct |
485 ms |
16476 KB |
Output is correct |
16 |
Correct |
315 ms |
1308 KB |
Output is correct |
17 |
Correct |
70 ms |
1100 KB |
Output is correct |
18 |
Correct |
53 ms |
1068 KB |
Output is correct |
19 |
Correct |
372 ms |
8680 KB |
Output is correct |
20 |
Correct |
153 ms |
1144 KB |
Output is correct |