Submission #839476

# Submission time Handle Problem Language Result Execution time Memory
839476 2023-08-30T06:20:11 Z adaawf Selling RNA Strands (JOI16_selling_rna) C++14
100 / 100
385 ms 205236 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> vv[2000005];
int t[2][4][2000005], a[2000005], b[2000005], n, m, d[2];
string s[2000005];
int check(char c) {
    if (c == 'A') return 0;
    if (c == 'C') return 1;
    if (c == 'G') return 2;
    return 3;
}
void add(string s, int j, int h, int flag) {
	int k = 1;
	for (int i = 0; i < s.size(); i++) {
	    int c;
        if (flag == 1) c = check(s[s.size() - i - 1]);
        else c = check(s[i]);
		if (t[h][c][k] == 0) t[h][c][k] = d[h]++;
		k = t[h][c][k];
		if (h == 0) {
			if (a[k] == 0) a[k] = j;
			b[k] = max(b[k], j);
		}
		else vv[k].push_back(j);
	}
}
int get(string s, int h, int flag) {
	int k = 1;
	for (int i = 0; i < s.size(); i++) {
	    int c;
        if (flag == 1) c = check(s[s.size() - i - 1]);
        else c = check(s[i]);
		k = t[h][c][k];
		if (k == 0) return 0;
	}
	return k;
}
int main() {
	cin >> n >> m;
	d[0] = d[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, 0);
		add(s[i], i + 1, 1, 1);
	}
	for (int i = 0; i < m; i++) {
		string s, t;
		cin >> s >> t;
		int h = get(s, 0, 0), k = get(t, 1, 1);
		int g = lower_bound(vv[k].begin(), vv[k].end(), a[h]) - vv[k].begin(), l = upper_bound(vv[k].begin(), vv[k].end(), b[h]) - vv[k].begin();
		cout << max(0, l - g) << '\n';
	}
}

Compilation message

selling_rna.cpp: In function 'void add(std::string, int, int, int)':
selling_rna.cpp:16:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  for (int i = 0; i < s.size(); i++) {
      |                  ~~^~~~~~~~~~
selling_rna.cpp: In function 'int get(std::string, int, int)':
selling_rna.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for (int i = 0; i < s.size(); i++) {
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 60 ms 109896 KB Output is correct
2 Correct 45 ms 109876 KB Output is correct
3 Correct 46 ms 109900 KB Output is correct
4 Correct 45 ms 109956 KB Output is correct
5 Correct 45 ms 109908 KB Output is correct
6 Correct 47 ms 109908 KB Output is correct
7 Correct 45 ms 109884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 222 ms 205236 KB Output is correct
2 Correct 227 ms 200304 KB Output is correct
3 Correct 163 ms 169592 KB Output is correct
4 Correct 162 ms 167156 KB Output is correct
5 Correct 198 ms 197524 KB Output is correct
6 Correct 192 ms 198732 KB Output is correct
7 Correct 149 ms 120544 KB Output is correct
8 Correct 235 ms 155884 KB Output is correct
9 Correct 220 ms 156412 KB Output is correct
10 Correct 169 ms 155096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 110776 KB Output is correct
2 Correct 104 ms 110664 KB Output is correct
3 Correct 113 ms 110692 KB Output is correct
4 Correct 101 ms 110516 KB Output is correct
5 Correct 101 ms 110716 KB Output is correct
6 Correct 125 ms 110704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 109896 KB Output is correct
2 Correct 45 ms 109876 KB Output is correct
3 Correct 46 ms 109900 KB Output is correct
4 Correct 45 ms 109956 KB Output is correct
5 Correct 45 ms 109908 KB Output is correct
6 Correct 47 ms 109908 KB Output is correct
7 Correct 45 ms 109884 KB Output is correct
8 Correct 222 ms 205236 KB Output is correct
9 Correct 227 ms 200304 KB Output is correct
10 Correct 163 ms 169592 KB Output is correct
11 Correct 162 ms 167156 KB Output is correct
12 Correct 198 ms 197524 KB Output is correct
13 Correct 192 ms 198732 KB Output is correct
14 Correct 149 ms 120544 KB Output is correct
15 Correct 235 ms 155884 KB Output is correct
16 Correct 220 ms 156412 KB Output is correct
17 Correct 169 ms 155096 KB Output is correct
18 Correct 129 ms 110776 KB Output is correct
19 Correct 104 ms 110664 KB Output is correct
20 Correct 113 ms 110692 KB Output is correct
21 Correct 101 ms 110516 KB Output is correct
22 Correct 101 ms 110716 KB Output is correct
23 Correct 125 ms 110704 KB Output is correct
24 Correct 254 ms 188592 KB Output is correct
25 Correct 292 ms 188780 KB Output is correct
26 Correct 252 ms 187704 KB Output is correct
27 Correct 184 ms 160400 KB Output is correct
28 Correct 385 ms 131788 KB Output is correct
29 Correct 268 ms 115280 KB Output is correct