#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <cassert>
#include <algorithm>
#define rep(i,n) for (int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define _1 first
#define _2 second
using namespace std;
typedef pair<int, int> P;
string convert(string s) {
string o = "";
for (char c : s) {
if (c == 'A') o += 'a';
else if (c == 'G') o += 'b';
else if (c == 'C') o += 'c';
else if (c == 'U') o += 'd';
else abort();
}
return o;
}
string read() {
string s;
cin >> s;
return convert(s);
}
int N, Q;
string S[100000], Srev[100000];
string Qpre[100000], Qsuf[100000];
bool is_prefix_of(const string &S, const string &T) {
if (T.size() > S.size()) return false;
rep(i, T.size()) if (T[i] != S[i]) return false;
return true;
}
int main() {
cin >> N >> Q;
rep(i, N) {
S[i] = read();
Srev[i] = string(S[i]);
reverse(all(Srev[i]));
}
rep(i, Q) Qpre[i] = read(), Qsuf[i] = read(), reverse(all(Qsuf[i]));
rep(i, Q) {
int s = 0;
rep(j, N) {
if (is_prefix_of(S[j], Qpre[i]) && is_prefix_of(Srev[j], Qsuf[i])) s++;
}
cout << s << "\n";
}
return 0;
}
Compilation message
selling_rna.cpp: In function 'bool is_prefix_of(const string&, const string&)':
selling_rna.cpp:8:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,n) for (int i=0; i<(n); i++)
^
selling_rna.cpp:38:3: note: in expansion of macro 'rep'
rep(i, T.size()) if (T[i] != S[i]) return false;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
14516 KB |
Output is correct |
2 |
Correct |
0 ms |
14516 KB |
Output is correct |
3 |
Correct |
6 ms |
14516 KB |
Output is correct |
4 |
Correct |
6 ms |
14516 KB |
Output is correct |
5 |
Correct |
3 ms |
14516 KB |
Output is correct |
6 |
Correct |
0 ms |
14516 KB |
Output is correct |
7 |
Correct |
0 ms |
14516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1099 ms |
22308 KB |
Output is correct |
2 |
Execution timed out |
1500 ms |
22304 KB |
Execution timed out |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1500 ms |
14516 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
14516 KB |
Output is correct |
2 |
Correct |
0 ms |
14516 KB |
Output is correct |
3 |
Correct |
6 ms |
14516 KB |
Output is correct |
4 |
Correct |
6 ms |
14516 KB |
Output is correct |
5 |
Correct |
3 ms |
14516 KB |
Output is correct |
6 |
Correct |
0 ms |
14516 KB |
Output is correct |
7 |
Correct |
0 ms |
14516 KB |
Output is correct |
8 |
Correct |
1099 ms |
22308 KB |
Output is correct |
9 |
Execution timed out |
1500 ms |
22304 KB |
Execution timed out |
10 |
Halted |
0 ms |
0 KB |
- |