#include <bits/stdc++.h>
using namespace std;
int N;
vector<string> arr;
map<string, int> freq;
int valid(string s) {
int len = (int)s.size();
int ans = 0;
set<string> unique;
for (int i = 0; i < len; i++) {
for (int j = i; j < len; j++) {
string r = s.substr(i, j-i+1);
unique.insert(r);
}
}
for (auto it = unique.begin(); it != unique.end(); it++) {
if ((int)(*it).size() == len) {
ans += freq[*it]-1;
continue;
}
ans += freq[*it];
}
return ans;
}
int main() {
cin >> N;
arr.resize(N+1);
for (int i = 1; i <= N; i++) {
cin >> arr[i];
freq[arr[i]]++;
}
int ans = 0;
for (int i = 1; i <= N; i++) {
ans += valid(arr[i]);
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
10 ms |
716 KB |
Output is correct |
6 |
Correct |
13 ms |
624 KB |
Output is correct |
7 |
Correct |
17 ms |
1356 KB |
Output is correct |
8 |
Correct |
28 ms |
2164 KB |
Output is correct |
9 |
Correct |
75 ms |
2444 KB |
Output is correct |
10 |
Correct |
154 ms |
7584 KB |
Output is correct |
11 |
Correct |
118 ms |
4300 KB |
Output is correct |
12 |
Correct |
348 ms |
16716 KB |
Output is correct |
13 |
Correct |
238 ms |
2844 KB |
Output is correct |
14 |
Correct |
274 ms |
14908 KB |
Output is correct |
15 |
Correct |
325 ms |
16428 KB |
Output is correct |
16 |
Correct |
211 ms |
1296 KB |
Output is correct |
17 |
Correct |
62 ms |
1108 KB |
Output is correct |
18 |
Correct |
46 ms |
1108 KB |
Output is correct |
19 |
Correct |
239 ms |
8600 KB |
Output is correct |
20 |
Correct |
106 ms |
1212 KB |
Output is correct |