Submission #788719

# Submission time Handle Problem Language Result Execution time Memory
788719 2023-07-20T14:18:51 Z Dan4Life Selling RNA Strands (JOI16_selling_rna) C++17
100 / 100
336 ms 205196 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> V[N];
int T[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(!T[t][c][v]) T[t][c][v]=I[t]++;
		v = T[t][c][v];
		if(!t){
			if(!L[v]) L[v]=j;
			R[v]=max(R[v],j);
		}
		else V[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 = T[t][c][v]; if(!v) return 0;
	}
	return v;
}
 
int32_t main()
{
	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 I = get(s,0), I2=get(t,1,1);
		int l = L[I], r=R[I];
		int p1 = lower_bound(all(V[I2]),l)-begin(V[I2]);
		int p2 = upper_bound(all(V[I2]),r)-begin(V[I2]);
		cout << max(0, p2-p1) << "\n";
	}
}

Compilation message

selling_rna.cpp: In function 'int32_t main()':
selling_rna.cpp:40:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   40 |  for(int i = 0; i < n; i++)
      |  ^~~
selling_rna.cpp:41:16: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   41 |   cin >> s[i]; sort(s,s+n);
      |                ^~~~
# Verdict Execution time Memory Grader output
1 Correct 47 ms 109896 KB Output is correct
2 Correct 46 ms 109908 KB Output is correct
3 Correct 46 ms 109956 KB Output is correct
4 Correct 46 ms 109972 KB Output is correct
5 Correct 48 ms 109908 KB Output is correct
6 Correct 45 ms 109908 KB Output is correct
7 Correct 47 ms 109884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 226 ms 205196 KB Output is correct
2 Correct 222 ms 200296 KB Output is correct
3 Correct 169 ms 169652 KB Output is correct
4 Correct 159 ms 167300 KB Output is correct
5 Correct 190 ms 197420 KB Output is correct
6 Correct 188 ms 198832 KB Output is correct
7 Correct 151 ms 120372 KB Output is correct
8 Correct 229 ms 155876 KB Output is correct
9 Correct 214 ms 156428 KB Output is correct
10 Correct 169 ms 155212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 110776 KB Output is correct
2 Correct 97 ms 110724 KB Output is correct
3 Correct 113 ms 110668 KB Output is correct
4 Correct 100 ms 110548 KB Output is correct
5 Correct 102 ms 110772 KB Output is correct
6 Correct 118 ms 110880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 109896 KB Output is correct
2 Correct 46 ms 109908 KB Output is correct
3 Correct 46 ms 109956 KB Output is correct
4 Correct 46 ms 109972 KB Output is correct
5 Correct 48 ms 109908 KB Output is correct
6 Correct 45 ms 109908 KB Output is correct
7 Correct 47 ms 109884 KB Output is correct
8 Correct 226 ms 205196 KB Output is correct
9 Correct 222 ms 200296 KB Output is correct
10 Correct 169 ms 169652 KB Output is correct
11 Correct 159 ms 167300 KB Output is correct
12 Correct 190 ms 197420 KB Output is correct
13 Correct 188 ms 198832 KB Output is correct
14 Correct 151 ms 120372 KB Output is correct
15 Correct 229 ms 155876 KB Output is correct
16 Correct 214 ms 156428 KB Output is correct
17 Correct 169 ms 155212 KB Output is correct
18 Correct 138 ms 110776 KB Output is correct
19 Correct 97 ms 110724 KB Output is correct
20 Correct 113 ms 110668 KB Output is correct
21 Correct 100 ms 110548 KB Output is correct
22 Correct 102 ms 110772 KB Output is correct
23 Correct 118 ms 110880 KB Output is correct
24 Correct 241 ms 188620 KB Output is correct
25 Correct 285 ms 188744 KB Output is correct
26 Correct 233 ms 187692 KB Output is correct
27 Correct 182 ms 160552 KB Output is correct
28 Correct 336 ms 131744 KB Output is correct
29 Correct 254 ms 115236 KB Output is correct