#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,m;
cin >> n >> m;
vector<pair<string,int>> source(n);
vector<pair<string,int>> rsource(n);
for (int i = 0;i<n;i++){
cin >> source[i].first;
source[i].second = i;
rsource[i] = source[i];
reverse(rsource[i].first.begin(),rsource[i].first.end());
}
sort(source.begin(),source.end());
sort(rsource.begin(),rsource.end());
vector<int> t(n,-1);
int cur = 1;
while (m--){
string p,q;
cin >> p >> q;
int ans = 0;
reverse(q.begin(),q.end());
auto a = lower_bound(source.begin(),source.end(),make_pair(p,0));
p[p.size()-1]++;
auto b = lower_bound(source.begin(),source.end(),make_pair(p,0));
for (;a!=b;a++){
t[(*a).second] = cur;
}
a = lower_bound(rsource.begin(),rsource.end(),make_pair(q,0));
q[q.size()-1]++;
b = lower_bound(rsource.begin(),rsource.end(),make_pair(q,0));
for (;a!=b;a++){
if (t[(*a).second] == cur){
ans++;
}
}
cout << ans << "\n";
cur++;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
4564 KB |
Output is correct |
2 |
Correct |
66 ms |
8736 KB |
Output is correct |
3 |
Correct |
48 ms |
8688 KB |
Output is correct |
4 |
Correct |
61 ms |
8732 KB |
Output is correct |
5 |
Correct |
23 ms |
5836 KB |
Output is correct |
6 |
Correct |
19 ms |
5840 KB |
Output is correct |
7 |
Correct |
47 ms |
8940 KB |
Output is correct |
8 |
Correct |
43 ms |
10700 KB |
Output is correct |
9 |
Correct |
38 ms |
10712 KB |
Output is correct |
10 |
Correct |
118 ms |
8148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1598 ms |
4484 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
19 ms |
4564 KB |
Output is correct |
9 |
Correct |
66 ms |
8736 KB |
Output is correct |
10 |
Correct |
48 ms |
8688 KB |
Output is correct |
11 |
Correct |
61 ms |
8732 KB |
Output is correct |
12 |
Correct |
23 ms |
5836 KB |
Output is correct |
13 |
Correct |
19 ms |
5840 KB |
Output is correct |
14 |
Correct |
47 ms |
8940 KB |
Output is correct |
15 |
Correct |
43 ms |
10700 KB |
Output is correct |
16 |
Correct |
38 ms |
10712 KB |
Output is correct |
17 |
Correct |
118 ms |
8148 KB |
Output is correct |
18 |
Execution timed out |
1598 ms |
4484 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |