#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;
int n, m;
string s[maxn];
bool match(string s, string pre, string suf) {
if (pre.size() > s.size()) return false;
if (suf.size() > s.size()) return false;
int n = s.length();
for (int i=0; i<(int)pre.size(); i++) {
if (s[i]!=pre[i]) return false;
}
for (int i=0; i<(int)suf.size(); i++) {
if (suf[(int)suf.size()-i-1] != s[n-1-i]) return false;
}
return true;
}
int solve(string p, string q) {
int res = 0;
for (int i=0; i<n; i++) {
res += match(s[i], p, q);
}
return res;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>m;
for (int i=0; i<n; i++) {
cin>>s[i];
}
for (int i=0; i<m; i++) {
string p, q;
cin>>p>>q;
cout<<solve(p,q)<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
31616 KB |
Output is correct |
2 |
Correct |
21 ms |
31616 KB |
Output is correct |
3 |
Correct |
21 ms |
31616 KB |
Output is correct |
4 |
Correct |
22 ms |
31616 KB |
Output is correct |
5 |
Correct |
20 ms |
31612 KB |
Output is correct |
6 |
Correct |
20 ms |
31616 KB |
Output is correct |
7 |
Correct |
21 ms |
31616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1587 ms |
37880 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1590 ms |
32088 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
31616 KB |
Output is correct |
2 |
Correct |
21 ms |
31616 KB |
Output is correct |
3 |
Correct |
21 ms |
31616 KB |
Output is correct |
4 |
Correct |
22 ms |
31616 KB |
Output is correct |
5 |
Correct |
20 ms |
31612 KB |
Output is correct |
6 |
Correct |
20 ms |
31616 KB |
Output is correct |
7 |
Correct |
21 ms |
31616 KB |
Output is correct |
8 |
Execution timed out |
1587 ms |
37880 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |