#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("popcnt")
int N = 2*1e6+1;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n, m;
cin >> n >> m;
vector<array<int, 4>> prefix(N, {-1, -1, -1, -1});
vector<array<int, 4>> suffix(N, {-1, -1, -1, -1});
vector<int> preind(N, -1);
vector<int> sufind(N, -1);
vector<int> alph(100);
alph['A'] = 0;
alph['C'] = 1;
alph['G'] = 2;
alph['U'] = 3;
vector<string> ns(n);
vector<int> pind(m);
vector<int> sind(m);
int cp = 0;
int cs = 0;
int dp = 0;
int ds = 0;
for (int i = 0; i < n; i++) cin >> ns[i];
for (int i = 0; i < m; i++)
{
string a, b;
cin >> a >> b;
reverse(b.begin(), b.end());
int curr = 0;
for (char c:a)
{
int next = alph[c];
if (prefix[curr][next]==-1)
{
prefix[curr][next] = ++cp;
}
curr = prefix[curr][next];
}
if (preind[curr]==-1)
{
preind[curr] = ++dp;
pind[i] = dp;
}
else pind[i] = preind[curr];
curr = 0;
for (char c:b)
{
int next = alph[c];
if (suffix[curr][next]==-1)
{
suffix[curr][next] = ++cs;
}
curr = suffix[curr][next];
}
if (sufind[curr] ==-1)
{
sufind[curr] = ++ds;
sind[i] = ds;
}
else sind[i] =sufind[curr];
}
vector<bitset<50000>> pnodes(dp);
vector<bitset<50000>> snodes(ds);
vector<vector<int>> p2nodes(N);
vector<vector<int>> s2nodes(N);
for (int i = 0; i < n; i++)
{
int curr = 0;
for (char c:ns[i])
{
int next = alph[c];
curr = prefix[curr][next];
if (curr == -1) break;
if (preind[curr]!=-1) pnodes[preind[curr]][i] = 1;
}
reverse(ns[i].begin(), ns[i].end());
curr = 0;
for (char c:ns[i])
{
int next = alph[c];
curr = suffix[curr][next];
if (curr == -1) break;
if (sufind[curr]!=-1) snodes[sufind[curr]][i] = 1;
}
}
for (int i = 0; i < m; i++)
{
int sol = (snodes[sind[i]]&pnodes[pind[i]]).count();
int p1 = 0;
int p2 = 0;
int pi = pind[i];
int si = sind[i];
while (p1 < p2nodes[pi].size() && p2 < s2nodes[si].size())
{
if (p2nodes[pi][p1] == s2nodes[si][p2])
{
p1++;
p2++;
sol++;
}
else if (p2nodes[pi][p1] > s2nodes[si][p2]) p2++;
else p1++;
}
cout << sol << "\n";
}
return 0;
}
Compilation message
selling_rna.cpp: In function 'int main()':
selling_rna.cpp:120:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
120 | while (p1 < p2nodes[pi].size() && p2 < s2nodes[si].size())
| ~~~^~~~~~~~~~~~~~~~~~~~
selling_rna.cpp:120:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
120 | while (p1 < p2nodes[pi].size() && p2 < s2nodes[si].size())
| ~~~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
173136 KB |
Output is correct |
2 |
Incorrect |
37 ms |
173128 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
185608 KB |
Output is correct |
2 |
Correct |
70 ms |
184392 KB |
Output is correct |
3 |
Runtime error |
137 ms |
184148 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
157 ms |
175344 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
173136 KB |
Output is correct |
2 |
Incorrect |
37 ms |
173128 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |