#include <bits/stdc++.h>
using namespace std;
#define islam_zymchybekov void solve()
#define ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define endl '\n'
#define nl cout<<'\n';
#define int long long
#define stg string
#define yes cout<<"Yes\n";
#define no cout<<"No\n";
typedef vector<int> vi;
typedef pair<int,int> pi;
int c,n,m,i,j,k,x,y,cnt=0,res=0,l=0,mx=-1,sum=0,nx=-1;
islam_zymchybekov{
string s, s1;
cin >> n >> m;
if(n<5001){
vector<string>v(n);
for(i=0;i<n;i++){
cin>>v[i];
}
for(i=0;i<m;i++){
cin>>s>>s1;
int ans=0;
for(j=0;j<n;j++){
if(v[j].size()>=max(s.size(),s1.size())){
if(v[j].substr(0,s.size())==s){
if( v[j].substr(v[j].size()-s1.size())==s1){
ans++;
}
}
}
}
cout<<ans;nl;
}
}
else{
unordered_map<string, int> mp;
for (int i = 0; i < n; i++) {
cin >> s;
mp[s]++;
}
for (int i = 0; i < m; i++) {
cin >> s >> s1;
int ans = 0;
int len_s = s.size();
int len_s1 = s1.size();
for (auto &it : mp) {
string curr = it.first;
int len_curr = curr.size();
if (len_curr >= max(len_s, len_s1)) {
if (curr.substr(0, len_s) == s && curr.substr(len_curr - len_s1) == s1) {
ans += it.second;
}
}
}
cout << ans; nl;
}
}
}
main(){
int T = 1;
while(T--){
solve();
}
return 0;
}
Compilation message
selling_rna.cpp:77:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
77 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
181 ms |
3384 KB |
Output is correct |
2 |
Correct |
677 ms |
3732 KB |
Output is correct |
3 |
Correct |
243 ms |
3408 KB |
Output is correct |
4 |
Correct |
303 ms |
3408 KB |
Output is correct |
5 |
Correct |
560 ms |
2368 KB |
Output is correct |
6 |
Correct |
622 ms |
2396 KB |
Output is correct |
7 |
Correct |
535 ms |
2612 KB |
Output is correct |
8 |
Correct |
1111 ms |
3016 KB |
Output is correct |
9 |
Correct |
948 ms |
3020 KB |
Output is correct |
10 |
Correct |
1397 ms |
3156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
496 KB |
Output is correct |
2 |
Correct |
780 ms |
1008 KB |
Output is correct |
3 |
Correct |
759 ms |
808 KB |
Output is correct |
4 |
Correct |
60 ms |
752 KB |
Output is correct |
5 |
Correct |
582 ms |
548 KB |
Output is correct |
6 |
Correct |
598 ms |
1000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
181 ms |
3384 KB |
Output is correct |
9 |
Correct |
677 ms |
3732 KB |
Output is correct |
10 |
Correct |
243 ms |
3408 KB |
Output is correct |
11 |
Correct |
303 ms |
3408 KB |
Output is correct |
12 |
Correct |
560 ms |
2368 KB |
Output is correct |
13 |
Correct |
622 ms |
2396 KB |
Output is correct |
14 |
Correct |
535 ms |
2612 KB |
Output is correct |
15 |
Correct |
1111 ms |
3016 KB |
Output is correct |
16 |
Correct |
948 ms |
3020 KB |
Output is correct |
17 |
Correct |
1397 ms |
3156 KB |
Output is correct |
18 |
Correct |
109 ms |
496 KB |
Output is correct |
19 |
Correct |
780 ms |
1008 KB |
Output is correct |
20 |
Correct |
759 ms |
808 KB |
Output is correct |
21 |
Correct |
60 ms |
752 KB |
Output is correct |
22 |
Correct |
582 ms |
548 KB |
Output is correct |
23 |
Correct |
598 ms |
1000 KB |
Output is correct |
24 |
Execution timed out |
1556 ms |
5308 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |