#include<bits/stdc++.h>
using namespace std;
unordered_map < string, int > q;
inline void add(string &s){
unordered_map < string, int > used;
for(int i = 0; i < (int)s.size(); i++){
string t;
for(int j = i; j < (int)s.size(); j++){
t += s[j];
if(used.find(t) == used.end()){
q[t] += 1;
used[t] = true;
}
}
}
}
inline void del(string &s){
unordered_map < string, int > used;
for(int i = 0; i < (int)s.size(); i++){
string t;
for(int j = i; j < (int)s.size(); j++){
t += s[j];
if(used.find(t) == used.end()){
q[t] -= 1;
used[t] = false;
}
}
}
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin >> n;
string s[n];
for(int i = 0; i < n; i++){
cin >> s[i];
add(s[i]);
}
int ans = 0;
for(int i = 0; i < n; i++){
del(s[i]);
ans += q[s[i]];
add(s[i]);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
21 ms |
768 KB |
Output is correct |
6 |
Correct |
30 ms |
768 KB |
Output is correct |
7 |
Correct |
42 ms |
1536 KB |
Output is correct |
8 |
Correct |
86 ms |
2172 KB |
Output is correct |
9 |
Correct |
185 ms |
2380 KB |
Output is correct |
10 |
Correct |
434 ms |
7292 KB |
Output is correct |
11 |
Correct |
324 ms |
4056 KB |
Output is correct |
12 |
Correct |
969 ms |
15668 KB |
Output is correct |
13 |
Correct |
529 ms |
2680 KB |
Output is correct |
14 |
Correct |
739 ms |
14264 KB |
Output is correct |
15 |
Execution timed out |
1047 ms |
15420 KB |
Time limit exceeded |
16 |
Correct |
634 ms |
1172 KB |
Output is correct |
17 |
Correct |
249 ms |
1016 KB |
Output is correct |
18 |
Correct |
200 ms |
1000 KB |
Output is correct |
19 |
Correct |
705 ms |
8172 KB |
Output is correct |
20 |
Correct |
371 ms |
1276 KB |
Output is correct |