Submission #1034692

#TimeUsernameProblemLanguageResultExecution timeMemory
1034692baotoan655Selling RNA Strands (JOI16_selling_rna)C++17
10 / 100
1585 ms377668 KiB
#include <bits/stdc++.h> #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } #define FOR(i, a, b) for(int i = (a); i <= (b); ++i) #define REV(i, b, a) for(int i = (b); i >= (a); --i) #define REP(i, n) for(int i = 0; i < (n); ++i) #define ll long long #define fi first #define se second using namespace std; set<int> empty_set; int n, q; int num[26]; struct trie { struct node { node* con[4]; set<int> se; node() { for(int i = 0; i < 4; ++i) con[i] = NULL; se.clear(); }; }; node* root; trie() { root = new node(); }; void add_string(const string &s, int id) { node* pos = root; for(char ch : s) { int c = num[ch - 'A']; if(pos->con[c] == NULL) pos->con[c] = new node(); pos = pos->con[c]; pos->se.insert(id); } }; set<int> get(const string &s) { node* pos = root; for(char ch : s) { int c = num[ch - 'A']; if(pos->con[c] == NULL) return empty_set; pos = pos->con[c]; } return pos->se; } } tr1, tr2; void solve(int tc) { num['A' - 'A'] = 0; num['U' - 'A'] = 1; num['G' - 'A'] = 2; num['C' - 'A'] = 3; cin >> n >> q; string str; FOR(i, 1, n) { cin >> str; tr1.add_string(str, i); reverse(str.begin(), str.end()); tr2.add_string(str, i); } while(q--) { string s1, s2; cin >> s1 >> s2; reverse(s2.begin(), s2.end()); set<int> se1 = tr1.get(s1); set<int> se2 = tr2.get(s2); int ans = 0; for(int x : se1) { if(se2.find(x) != se2.end()) ++ans; } cout << ans << '\n'; } return; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); file("A"); int tc = 1; // cin >> tc; for(int i = 1; i <= tc; ++i) solve(tc); return (0); }

Compilation message (stderr)

selling_rna.cpp: In function 'int32_t main()':
selling_rna.cpp:2:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
selling_rna.cpp:82:5: note: in expansion of macro 'file'
   82 |     file("A");
      |     ^~~~
selling_rna.cpp:2:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
selling_rna.cpp:82:5: note: in expansion of macro 'file'
   82 |     file("A");
      |     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...