Submission #112374

# Submission time Handle Problem Language Result Execution time Memory
112374 2019-05-19T07:05:53 Z Mahdi_Jfri Selling RNA Strands (JOI16_selling_rna) C++14
0 / 100
785 ms 860704 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back

const int maxn = 4e6 + 20;
const int maxs = 5;

vector<pair<int , int> > query[maxn];

string s[maxn] , a[maxn] , b[maxn];

int nxt[maxn][maxs] , mx[maxn] , sz[maxn] , id , res[maxn];

void add(int ind)
{
	int p = 0;
	for(int ch : s[ind])
	{
		if(!nxt[p][ch])
			nxt[p][ch] = ++id;

		while(id >= maxn);

		mx[p] = ind;
		sz[p]++;
		p = nxt[p][ch];
	}

	mx[p] = ind;
	sz[p]++;
}

pair<int , int> fn(string s)
{
	int p = 0;
	for(int ch : s)
	{
		if(!nxt[p][ch])
			return make_pair(0 , 0);

		p = nxt[p][ch];
	}

	return {mx[p] , sz[p]};
}

void reval(string &s)
{
	for(auto &ch : s)
	{
		if(ch == 'A')
			ch = 0;
		else if(ch == 'G')
			ch = 1;
		else if(ch == 'C')
			ch = 2;
		else
			ch = 3;
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n , q;
	cin >> n >> q;

	for(int i = 1; i <= n; i++)
		cin >> s[i];
	sort(s + 1 , s + n + 1);

	for(int i = 1; i <= n; i++)
		add(i);

	for(int i = 0; i < q; i++)
	{
		cin >> a[i] >> b[i];
		reverse(b[i].begin() , b[i].end());

		auto tmp = fn(a[i]);
		int r = tmp.first , l = tmp.first - tmp.second;
		query[r].pb({i , 1});
		query[l].pb({i ,-1});
	}

	memset(nxt , 0 , sizeof nxt);
	memset(mx , 0 , sizeof mx);
	memset(sz , 0 , sizeof sz);
	id = 0;

	for(int i = 1; i <= n; i++)
	{
		reverse(s[i].begin() , s[i].end());
		add(i);

		for(auto tmp : query[i])
			res[tmp.first] += tmp.second * fn(b[tmp.first]).second;
	}

	for(int i = 0; i < q; i++)
		cout << res[i] << endl;
}














# Verdict Execution time Memory Grader output
1 Incorrect 528 ms 579576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 785 ms 860704 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 582 ms 581292 KB Output is correct
2 Incorrect 518 ms 580700 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 528 ms 579576 KB Output isn't correct
2 Halted 0 ms 0 KB -