Submission #788715

# Submission time Handle Problem Language Result Execution time Memory
788715 2023-07-20T14:12:47 Z Dan4Life Selling RNA Strands (JOI16_selling_rna) C++17
100 / 100
183 ms 204468 KB
#include <bits/stdc++.h>
using namespace std;
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
const int N = (int)2e6+10;
vector<int> xd[N];
int trie[2][4][N];
int L[N], R[N];
int n, m, I[2];
string s[N];

void add(string &s, int j, int t, bool r=0){
	int v = 1;
	for(int i = 0; i < sz(s); i++){
		char u = s[r?sz(s)-1-i:i];
		int c = (u=='A'?0:u=='C'?1:u=='G'?2:3);
		if(!trie[t][c][v]) trie[t][c][v]=I[t]++;
		v = trie[t][c][v];
		if(!t){
			if(!L[v]) L[v]=j;
			R[v]=max(R[v],j);
		}
		else xd[v].push_back(j);
	}
}

int get(string &s, int t, bool r=0){
	int v = 1;
	for(int i = 0; i < sz(s); i++){
		char u = s[r?sz(s)-1-i:i];
		int c = (u=='A'?0:u=='C'?1:u=='G'?2:3);
		v = trie[t][c][v]; if(!v) return 0;
	}
	return v;
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m; I[0]=I[1]=2;
	for(int i = 0; i < n; i++) 
		cin >> s[i]; sort(s,s+n);
	for(int i = 0; i < n; i++)
		add(s[i],i+1,0),add(s[i],i+1,1,1);
	for(int i = 0; i < m; i++){
		string s, t; cin >> s >> t;
		int ind = get(s,0), ind2=get(t,1,1);
		int l = L[ind], r=R[ind];
		int pos1 = lower_bound(all(xd[ind2]),l)-begin(xd[ind2]);
		int pos2 = upper_bound(all(xd[ind2]),r)-begin(xd[ind2]);
		cout << max(0, pos2-pos1) << "\n";
	}
}

Compilation message

selling_rna.cpp: In function 'int32_t main()':
selling_rna.cpp:41:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   41 |  for(int i = 0; i < n; i++)
      |  ^~~
selling_rna.cpp:42:16: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   42 |   cin >> s[i]; sort(s,s+n);
      |                ^~~~
# Verdict Execution time Memory Grader output
1 Correct 46 ms 109976 KB Output is correct
2 Correct 48 ms 109912 KB Output is correct
3 Correct 46 ms 109964 KB Output is correct
4 Correct 46 ms 109852 KB Output is correct
5 Correct 46 ms 109900 KB Output is correct
6 Correct 46 ms 109976 KB Output is correct
7 Correct 51 ms 109900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 204468 KB Output is correct
2 Correct 183 ms 199624 KB Output is correct
3 Correct 107 ms 168624 KB Output is correct
4 Correct 105 ms 166368 KB Output is correct
5 Correct 166 ms 196996 KB Output is correct
6 Correct 150 ms 198416 KB Output is correct
7 Correct 75 ms 119976 KB Output is correct
8 Correct 139 ms 155480 KB Output is correct
9 Correct 132 ms 156160 KB Output is correct
10 Correct 122 ms 154956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 110944 KB Output is correct
2 Correct 60 ms 110804 KB Output is correct
3 Correct 63 ms 110796 KB Output is correct
4 Correct 59 ms 110540 KB Output is correct
5 Correct 62 ms 110728 KB Output is correct
6 Correct 65 ms 110776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 109976 KB Output is correct
2 Correct 48 ms 109912 KB Output is correct
3 Correct 46 ms 109964 KB Output is correct
4 Correct 46 ms 109852 KB Output is correct
5 Correct 46 ms 109900 KB Output is correct
6 Correct 46 ms 109976 KB Output is correct
7 Correct 51 ms 109900 KB Output is correct
8 Correct 162 ms 204468 KB Output is correct
9 Correct 183 ms 199624 KB Output is correct
10 Correct 107 ms 168624 KB Output is correct
11 Correct 105 ms 166368 KB Output is correct
12 Correct 166 ms 196996 KB Output is correct
13 Correct 150 ms 198416 KB Output is correct
14 Correct 75 ms 119976 KB Output is correct
15 Correct 139 ms 155480 KB Output is correct
16 Correct 132 ms 156160 KB Output is correct
17 Correct 122 ms 154956 KB Output is correct
18 Correct 64 ms 110944 KB Output is correct
19 Correct 60 ms 110804 KB Output is correct
20 Correct 63 ms 110796 KB Output is correct
21 Correct 59 ms 110540 KB Output is correct
22 Correct 62 ms 110728 KB Output is correct
23 Correct 65 ms 110776 KB Output is correct
24 Correct 164 ms 187796 KB Output is correct
25 Correct 174 ms 187972 KB Output is correct
26 Correct 164 ms 186856 KB Output is correct
27 Correct 115 ms 159908 KB Output is correct
28 Correct 161 ms 131076 KB Output is correct
29 Correct 93 ms 115264 KB Output is correct