#include<bits/stdc++.h>
using namespace std;
map < string, int > q;
inline void add(string &s){
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){
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 |
3 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 |
33 ms |
768 KB |
Output is correct |
6 |
Correct |
54 ms |
824 KB |
Output is correct |
7 |
Correct |
74 ms |
1656 KB |
Output is correct |
8 |
Correct |
112 ms |
2296 KB |
Output is correct |
9 |
Correct |
330 ms |
2552 KB |
Output is correct |
10 |
Correct |
804 ms |
7704 KB |
Output is correct |
11 |
Correct |
566 ms |
4444 KB |
Output is correct |
12 |
Execution timed out |
1064 ms |
16704 KB |
Time limit exceeded |
13 |
Correct |
982 ms |
2984 KB |
Output is correct |
14 |
Execution timed out |
1065 ms |
15188 KB |
Time limit exceeded |
15 |
Execution timed out |
1066 ms |
16716 KB |
Time limit exceeded |
16 |
Execution timed out |
1025 ms |
1400 KB |
Time limit exceeded |
17 |
Correct |
184 ms |
1244 KB |
Output is correct |
18 |
Correct |
131 ms |
1152 KB |
Output is correct |
19 |
Execution timed out |
1054 ms |
8756 KB |
Time limit exceeded |
20 |
Correct |
501 ms |
1400 KB |
Output is correct |