Submission #1163889

#TimeUsernameProblemLanguageResultExecution timeMemory
1163889hainam2k9Selling RNA Strands (JOI16_selling_rna)C++20
100 / 100
209 ms237128 KiB
#include <bits/stdc++.h> #define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0) #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout) #define ll long long #define ull unsigned long long #define i128 __int128 #define db long double #define sz(a) ((int)(a).size()) #define pb emplace_back #define pf emplace_front #define pob pop_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define fi first #define se second #define ins emplace #define mp make_pair using namespace std; const int MOD = 1e9+7, MAXN = 1e5+5; const string NAME = ""; struct Trie{ Trie* child[4]; vector<int> pos; Trie(){ child[0]=child[1]=child[2]=child[3]=NULL; pos.clear(); } }; int n,m; string s[MAXN]; inline void convert(string& s){ for(int i = 0; i<sz(s); ++i){ if(s[i]=='A') s[i]=0; else if(s[i]=='U') s[i]=1; else if(s[i]=='G') s[i]=2; else s[i]=3; } } inline void Add(Trie* root, string& s, int pos){ for(int i = 0; i<sz(s); ++i){ if(root->child[s[i]]==NULL) root->child[s[i]] = new Trie(); root=root->child[s[i]], root->pos.pb(pos); } } inline pair<int,int> getrange(Trie* root, string& s){ for(int i = 0; i<sz(s); ++i){ if(root->child[s[i]]==NULL) return {0,0}; root=root->child[s[i]]; } return {root->pos[0],root->pos.back()}; } inline int solve(Trie* root, string& s, pair<int,int> range){ if(range==mp(0,0)) return 0; for(int i = 0; i<sz(s); ++i){ if(root->child[s[i]]==NULL) return 0; root=root->child[s[i]]; } return ub(root->pos.begin(),root->pos.end(),range.se)-lb(root->pos.begin(),root->pos.end(),range.fi); } int main() { tt; if(fopen((NAME + ".INP").c_str(), "r")) fo; cin >> n >> m; for(int i = 1; i<=n; ++i){ cin >> s[i]; convert(s[i]); } sort(s+1,s+n+1); Trie* root = new Trie(); Trie* revroot = new Trie(); for(int i = 1; i<=n; ++i){ Add(root,s[i],i); reverse(s[i].begin(),s[i].end()); Add(revroot,s[i],i); } while(m--){ string x,y; cin >> x >> y; reverse(y.begin(),y.end()); convert(x), convert(y); cout << solve(revroot,y,getrange(root,x)) << "\n"; } }

Compilation message (stderr)

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
selling_rna.cpp:64:45: note: in expansion of macro 'fo'
   64 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
selling_rna.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
selling_rna.cpp:64:45: note: in expansion of macro 'fo'
   64 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...