Submission #933058

#TimeUsernameProblemLanguageResultExecution timeMemory
933058vjudge1Selling RNA Strands (JOI16_selling_rna)C++17
10 / 100
1553 ms972628 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); } } struct Trie { struct Node { ptr(Node) child[26]; 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[*it - 'A']) node->child[*it - 'A'] = ptr(Node) (new Node); node->child[*it - 'A']->suf.push_back(i); node = node->child[*it - 'A']; } } vector<ll> get(string& s) { ptr(Node) node = root; for (auto it = s.begin(); it != s.end(); it++) { if (!node->child[*it - 'A']) return {}; node = node->child[*it - 'A']; } 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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...