답안 #216492

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
216492 2020-03-27T11:35:16 Z islingr Selling RNA Strands (JOI16_selling_rna) C++14
100 / 100
287 ms 187488 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;

	T() { fill(all(nxt), nullptr); }

	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 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 250 ms 187488 KB Output is correct
2 Correct 256 ms 177528 KB Output is correct
3 Correct 79 ms 14584 KB Output is correct
4 Correct 80 ms 14460 KB Output is correct
5 Correct 187 ms 116524 KB Output is correct
6 Correct 183 ms 118264 KB Output is correct
7 Correct 77 ms 10872 KB Output is correct
8 Correct 175 ms 75688 KB Output is correct
9 Correct 151 ms 64888 KB Output is correct
10 Correct 117 ms 62712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 3444 KB Output is correct
2 Correct 42 ms 2936 KB Output is correct
3 Correct 40 ms 2932 KB Output is correct
4 Correct 31 ms 2556 KB Output is correct
5 Correct 47 ms 2432 KB Output is correct
6 Correct 46 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 250 ms 187488 KB Output is correct
9 Correct 256 ms 177528 KB Output is correct
10 Correct 79 ms 14584 KB Output is correct
11 Correct 80 ms 14460 KB Output is correct
12 Correct 187 ms 116524 KB Output is correct
13 Correct 183 ms 118264 KB Output is correct
14 Correct 77 ms 10872 KB Output is correct
15 Correct 175 ms 75688 KB Output is correct
16 Correct 151 ms 64888 KB Output is correct
17 Correct 117 ms 62712 KB Output is correct
18 Correct 42 ms 3444 KB Output is correct
19 Correct 42 ms 2936 KB Output is correct
20 Correct 40 ms 2932 KB Output is correct
21 Correct 31 ms 2556 KB Output is correct
22 Correct 47 ms 2432 KB Output is correct
23 Correct 46 ms 2808 KB Output is correct
24 Correct 263 ms 153720 KB Output is correct
25 Correct 287 ms 153848 KB Output is correct
26 Correct 247 ms 151896 KB Output is correct
27 Correct 98 ms 14072 KB Output is correct
28 Correct 247 ms 34800 KB Output is correct
29 Correct 132 ms 9584 KB Output is correct