# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
848303 | 2023-09-12T03:39:27 Z | quandlm | Selling RNA Strands (JOI16_selling_rna) | C++14 | 262 ms | 306512 KB |
#include <bits/stdc++.h> #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); } #define ll long long #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define REP(i, a, b) for (int i = (a); i >= (b); --i) #define pi pair<int,int> #define ple tuple<int,int,int> #define fi first #define se second #define ii make_pair #define isz(a) ((int)a.size()) #define ALL(a) a.begin(), a.end() #define heap_max(a) priority_queue<a> #define heap_max(a) priority_queue<a,vector<a>,greater<a>> using namespace std; //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; //template <typename T> //using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; const int N = 1e6 + 10; int n, q, l, r; string s[N]; int eval (char a) { if (a == 'A') return 0; if (a == 'C') return 1; if (a == 'G') return 2; return 3; } struct Trie { struct Node { Node* child[5]; int cnt; vector<int>mem; Node () { for (int i = 0; i <= 3; ++i) child[i] = nullptr; cnt = 0; mem = {}; }; }; Node* root = new Node(); void add (string s, int idx) { Node* p = root; for (int i = 0; i < isz(s); ++i) { int c = eval(s[i]); if (p -> child[c] == nullptr) { p -> child[c] = new Node(); } p = p -> child[c]; p -> mem.push_back(idx); } // p -> mem.push_back(idx); } void get_prefix (string s) { Node* p = root; for (int i = 0; i < isz(s); ++i) { int c = eval(s[i]); if (p -> child[c] == nullptr) { return; } p = p -> child[c]; } l = p -> mem.front(); r = p -> mem.back(); return; } int get_sufix (string s) { Node* p = root; for (int i = 0; i < isz(s); ++i) { int c = eval(s[i]); if (p -> child[c] == nullptr) { return 0; } p = p -> child[c]; } // cout << isz(p->mem) << endl; // for (int it : p->mem) cout << it << ' '; cout << endl; int left = lower_bound(ALL(p->mem), l)-p->mem.begin(); int right = upper_bound(ALL(p->mem), r)-p->mem.begin()-1; return right - left + 1; } } tree1, tree2; int main () { file("dynamic"); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q; FOR(i,1,n) cin >> s[i]; sort(s + 1, s + n + 1); for (int i = 1; i <= n; ++i) tree1.add(s[i], i); for (int i = 1; i <= n; ++i) { string rev = s[i]; reverse(ALL(rev)); tree2.add(rev, i); } while(q--) { string x, y; cin >> x >> y; l = -1; r = -1; tree1.get_prefix(x); if (l == -1) { cout << 0 << '\n'; continue; } reverse(ALL(y)); // cout << l << ' ' << r << endl; cout << tree2.get_sufix(y) << '\n'; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 31576 KB | Output is correct |
2 | Correct | 6 ms | 31576 KB | Output is correct |
3 | Correct | 7 ms | 31780 KB | Output is correct |
4 | Correct | 6 ms | 31580 KB | Output is correct |
5 | Correct | 8 ms | 31576 KB | Output is correct |
6 | Correct | 6 ms | 31576 KB | Output is correct |
7 | Correct | 7 ms | 31576 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 218 ms | 261040 KB | Output is correct |
2 | Correct | 211 ms | 252620 KB | Output is correct |
3 | Correct | 211 ms | 261456 KB | Output is correct |
4 | Correct | 219 ms | 251164 KB | Output is correct |
5 | Correct | 259 ms | 302160 KB | Output is correct |
6 | Correct | 262 ms | 306512 KB | Output is correct |
7 | Correct | 61 ms | 55888 KB | Output is correct |
8 | Correct | 216 ms | 208248 KB | Output is correct |
9 | Correct | 188 ms | 181680 KB | Output is correct |
10 | Correct | 146 ms | 175732 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 28 ms | 32980 KB | Output is correct |
2 | Correct | 21 ms | 33684 KB | Output is correct |
3 | Correct | 24 ms | 33624 KB | Output is correct |
4 | Correct | 20 ms | 33112 KB | Output is correct |
5 | Correct | 22 ms | 33624 KB | Output is correct |
6 | Correct | 25 ms | 33624 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 31576 KB | Output is correct |
2 | Correct | 6 ms | 31576 KB | Output is correct |
3 | Correct | 7 ms | 31780 KB | Output is correct |
4 | Correct | 6 ms | 31580 KB | Output is correct |
5 | Correct | 8 ms | 31576 KB | Output is correct |
6 | Correct | 6 ms | 31576 KB | Output is correct |
7 | Correct | 7 ms | 31576 KB | Output is correct |
8 | Correct | 218 ms | 261040 KB | Output is correct |
9 | Correct | 211 ms | 252620 KB | Output is correct |
10 | Correct | 211 ms | 261456 KB | Output is correct |
11 | Correct | 219 ms | 251164 KB | Output is correct |
12 | Correct | 259 ms | 302160 KB | Output is correct |
13 | Correct | 262 ms | 306512 KB | Output is correct |
14 | Correct | 61 ms | 55888 KB | Output is correct |
15 | Correct | 216 ms | 208248 KB | Output is correct |
16 | Correct | 188 ms | 181680 KB | Output is correct |
17 | Correct | 146 ms | 175732 KB | Output is correct |
18 | Correct | 28 ms | 32980 KB | Output is correct |
19 | Correct | 21 ms | 33684 KB | Output is correct |
20 | Correct | 24 ms | 33624 KB | Output is correct |
21 | Correct | 20 ms | 33112 KB | Output is correct |
22 | Correct | 22 ms | 33624 KB | Output is correct |
23 | Correct | 25 ms | 33624 KB | Output is correct |
24 | Correct | 195 ms | 224336 KB | Output is correct |
25 | Correct | 226 ms | 224692 KB | Output is correct |
26 | Correct | 193 ms | 222288 KB | Output is correct |
27 | Correct | 195 ms | 222324 KB | Output is correct |
28 | Correct | 145 ms | 79376 KB | Output is correct |
29 | Correct | 60 ms | 44860 KB | Output is correct |