# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1163889 | hainam2k9 | Selling RNA Strands (JOI16_selling_rna) | C++20 | 209 ms | 237128 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";
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |