Submission #541312

#TimeUsernameProblemLanguageResultExecution timeMemory
541312LittleOrangeSelling RNA Strands (JOI16_selling_rna)C++17
0 / 100
1572 ms8536 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(0);cin.tie(0); int n,m; cin >> n >> m; vector<pair<string,int>> source(n); vector<pair<string,int>> rsource(n); for (int i = 0;i<n;i++){ cin >> source[i].first; source[i].second = i; rsource[i] = source[i]; reverse(rsource[i].first.begin(),rsource[i].first.end()); } sort(source.begin(),source.end()); sort(rsource.begin(),rsource.end()); vector<int> t(n,-1); int cur = 1; while (m--){ string p,q; cin >> p >> q; int ans = 0; reverse(q.begin(),q.end()); auto a = lower_bound(source.begin(),source.end(),make_pair(p,0)); p[p.size()-1]++; auto b = lower_bound(source.begin(),source.end(),make_pair(p,0)); for (;a!=b;a++){ t[(*a).second] = cur; } a = lower_bound(rsource.begin(),rsource.end(),make_pair(q,0)); q[q.size()-1]++; b = lower_bound(rsource.begin(),rsource.end(),make_pair(q,0)); for (;a!=b;a++){ if (t[(*a).second] == cur){ ans++; } } cout << ans << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...