This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |