Submission #933061

#TimeUsernameProblemLanguageResultExecution timeMemory
933061vjudge1Selling RNA Strands (JOI16_selling_rna)C++17
35 / 100
1528 ms305744 KiB
#include <bits/stdc++.h> #define range(it, a, b) for (ll it = a; it < b; it++) #define all(x) begin(x), end(x) #define ll long long #define ull unsigned long long #define INF64 ((ll) 1 << 60) #define INF32 (1 << 30) #define mset multiset #define uset unordered_set #define umap unordered_map #define pqueue priority_queue #define ptr(A) shared_ptr<A> using namespace std; void setio (string name) { ios_base::sync_with_stdio(0); cin.tie(0); if (name.size()) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } ll cast (char c) { switch (c) { case 'A': return 0; case 'C': return 1; case 'G': return 2; case 'U': return 3; } } struct Trie { struct Node { ptr(Node) child[4]; vector<ll> suf; }; ptr(Node) root = ptr(Node) (new Node); void add(string& s, ll i) { ptr(Node) node = root; for (auto it = s.begin(); it != s.end(); it++) { if (!node->child[cast(*it)]) node->child[cast(*it)] = ptr(Node) (new Node); node->child[cast(*it)]->suf.push_back(i); node = node->child[cast(*it)]; } } vector<ll> get(string& s) { ptr(Node) node = root; for (auto it = s.begin(); it != s.end(); it++) { if (!node->child[cast(*it)]) return {}; node = node->child[cast(*it)]; } return node->suf; } }; ll n, m; vector<string> arr; string s, t; void solve() { cin >> n >> m; arr.resize(n); Trie tr; range(i, 0, n) { cin >> arr[i]; tr.add(arr[i], i); } while (m--) { cin >> s >> t; vector<ll> ans = tr.get(s); ll cnt = 0; for (ll& it : ans) { if (arr[it].size() >= t.size() && t == arr[it].substr(arr[it].size() - t.size(), t.size())) cnt++; } cout << cnt << '\n'; } } int main () { setio(""); ll t = 1; // cin >> t; while (t--) solve(); }

Compilation message (stderr)

selling_rna.cpp: In function 'void setio(std::string)':
selling_rna.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
selling_rna.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
selling_rna.cpp: In function 'long long int cast(char)':
selling_rna.cpp:38:1: warning: control reaches end of non-void function [-Wreturn-type]
   38 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...