Submission #1110728

#TimeUsernameProblemLanguageResultExecution timeMemory
1110728ljtunasSelling RNA Strands (JOI16_selling_rna)C++17
100 / 100
296 ms267568 KiB
// author : anhtun_hi , nqg #include <bits/stdc++.h> #define ll long long #define ii pair<ll, ll> #define fi first #define se second #define all(x) x.begin(), x.end() #define reset(h, v) memset(h, v, sizeof h) #define Forv(i, a) for(auto& i : a) #define For(i, a, b) for(int i = a; i <= b; ++i) #define Ford(i, a, b) for(int i = a; i >= b; --i) #define c_bit(i) __builtin_popcountll(i) #define Bit(mask, i) ((mask >> i) & 1LL) #define onbit(mask, i) ((mask) bitor (1LL << i)) #define offbit(mask, i) ((mask) &~ (1LL << i)) using namespace std; namespace std { template <typename T, int D> struct _vector : public vector <_vector <T, D - 1>> { static_assert(D >= 1, "Dimension must be positive!"); template <typename... Args> _vector(int n = 0, Args... args) : vector <_vector <T, D - 1>> (n, _vector <T, D - 1> (args...)) {} }; template <typename T> struct _vector <T, 1> : public vector <T> { _vector(int n = 0, const T& val = T()) : vector <T> (n, val) {} }; template <class A, class B> bool minimize(A &a, B b){return a > b ? a = b, true : false;} template <class A, class B> bool maximize(A &a, B b){return a < b ? a = b, true : false;} } const int dx[] = {0, 0, +1, -1}, dy[] = {-1, +1, 0, 0}, LOG = 20, base = 311, inf = 1e9 + 5; const int MAXN = 1e6 + 5; const ll mod = 1e9 + 7; const ll oo = 1e18; //#define int long long int n, q; string s[MAXN]; struct Node{ Node *child[4]; vector<int> s; Node(){ For(i, 0, 3) child[i] = nullptr; } }; Node *r1 = new Node(), *r2 = new Node(); int idx[50]; void add(const string& x, int i, Node *root){ Node *r = root; Forv(c, x){ r -> s.push_back(i); int k = idx[c - 'A']; if (r -> child[k] == nullptr) r -> child[k] = new Node(); // if(root == r2) cerr << c << '\n'; r = r -> child[k]; } r -> s.push_back(i); } ii get_range(const string& x, Node *root){ Node *r = root; Forv(c, x){ int k = idx[c - 'A']; if (r -> child[k] == nullptr) return {-1, -1}; r = r -> child[k]; } return {r -> s[0], r -> s.back()}; } int solve(const string& x, int L, int R){ Node *r = r2; Forv(c, x){ int k = idx[c - 'A']; if (r -> child[k] == nullptr) return 0; r = r -> child[k]; } return upper_bound(all(r -> s), R) - lower_bound(all(r -> s), L); } void Solve() { idx['A' - 'A'] = 0; idx['G' - 'A'] = 1; idx['C' - 'A'] = 2; idx['U' - 'A'] = 3; cin >> n >> q; For(i, 1, n) { cin >> s[i]; } sort(s + 1, s + n + 1); For(i, 1, n){ string x = s[i]; reverse(all(x)); add(s[i], i, r1); add(x, i, r2); } while (q--){ string a, b; cin >> a >> b; reverse(all(b)); ii tmp = get_range(a, r1); int l = tmp.fi, r = tmp.se; // cerr << l << ' ' << r << '\n'; // cerr << b << '\n'; if (!~l) cout << 0 << '\n'; else cout << solve(b, l, r) << '\n'; } } int32_t main() { cin.tie(0) -> sync_with_stdio(0); if(fopen("JOI16_selling_rna.inp", "r")) { freopen("JOI16_selling_rna.inp", "r", stdin); freopen("JOI16_selling_rna.out", "w", stdout); } int t = 1; // cin >> t; for (int test = 1; test <= t; test++) { Solve(); } return 0; }

Compilation message (stderr)

selling_rna.cpp: In function 'int32_t main()':
selling_rna.cpp:116:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |         freopen("JOI16_selling_rna.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
selling_rna.cpp:117:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |         freopen("JOI16_selling_rna.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...