답안 #896924

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
896924 2024-01-02T11:08:55 Z notyourbusiness Selling RNA Strands (JOI16_selling_rna) C++14
100 / 100
189 ms 187220 KB
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
 
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(x, v) for (auto &x : v)
 
#define lb(x...) lower_bound(x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
 
map<char, int> cmp = {{'A', 0}, {'C', 1}, {'G', 2}, {'U', 3}};
 
struct T {
	array<T*, 4> nxt;
	vector<int> idx;
 
	
	template<class it>
	void insert(it st, it en, int i) {
		idx.push_back(i);
		if (st == en) return;
		auto &x = nxt[cmp[*st]];
		if (!x) x = new T();
		x->insert(next(st), en, i);
	}
 
	template<class it>
	int query(it st, it en, int l, int r) { // [l, r)
		if (st == en)
			return lb(all(idx), r) - lb(all(idx), l);
		auto &x = nxt[cmp[*st]];
		return x ? x->query(next(st), en, l, r) : 0;
	}
} t;
 
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
	int n, m;
	cin >> n >> m;
	vector<string> s(n);
	rep(i, 0, n) cin >> s[i];
	sort(all(s));
	rep(i, 0, n) t.insert(rall(s[i]), i);
	while (m--) {
		string p, q; cin >> p >> q;
		int l = lb(all(s), p) - begin(s);
		++p.back();
		int r = lb(all(s), p) - begin(s);
		cout << t.query(rall(q), l, r) << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 177 ms 187220 KB Output is correct
2 Correct 166 ms 181188 KB Output is correct
3 Correct 41 ms 18260 KB Output is correct
4 Correct 39 ms 18048 KB Output is correct
5 Correct 120 ms 118788 KB Output is correct
6 Correct 126 ms 120336 KB Output is correct
7 Correct 40 ms 16040 KB Output is correct
8 Correct 113 ms 81736 KB Output is correct
9 Correct 95 ms 70576 KB Output is correct
10 Correct 74 ms 65848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 3032 KB Output is correct
2 Correct 20 ms 2652 KB Output is correct
3 Correct 24 ms 3032 KB Output is correct
4 Correct 18 ms 2648 KB Output is correct
5 Correct 20 ms 2520 KB Output is correct
6 Correct 26 ms 3032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 424 KB Output is correct
8 Correct 177 ms 187220 KB Output is correct
9 Correct 166 ms 181188 KB Output is correct
10 Correct 41 ms 18260 KB Output is correct
11 Correct 39 ms 18048 KB Output is correct
12 Correct 120 ms 118788 KB Output is correct
13 Correct 126 ms 120336 KB Output is correct
14 Correct 40 ms 16040 KB Output is correct
15 Correct 113 ms 81736 KB Output is correct
16 Correct 95 ms 70576 KB Output is correct
17 Correct 74 ms 65848 KB Output is correct
18 Correct 25 ms 3032 KB Output is correct
19 Correct 20 ms 2652 KB Output is correct
20 Correct 24 ms 3032 KB Output is correct
21 Correct 18 ms 2648 KB Output is correct
22 Correct 20 ms 2520 KB Output is correct
23 Correct 26 ms 3032 KB Output is correct
24 Correct 168 ms 157524 KB Output is correct
25 Correct 189 ms 157772 KB Output is correct
26 Correct 161 ms 155468 KB Output is correct
27 Correct 49 ms 17748 KB Output is correct
28 Correct 147 ms 39068 KB Output is correct
29 Correct 72 ms 12356 KB Output is correct