제출 #1156234

#제출 시각아이디문제언어결과실행 시간메모리
1156234NurislamSelling RNA Strands (JOI16_selling_rna)C++20
35 / 100
1576 ms4980 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
//#define all(x) x.begin(),x.end()
//#define rall(x) x.rbegin(),x.rend()
//#define ff first
//#define ss second
//#define pb push_back
//template<class T, class U> inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return true; } return false; }
//template<class T, class U> inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return true; } return false; }
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(l, r) uniform_int_distribution <int> (l, r)(rng)

const int inf = 1e9, mod = 1e9 + 7;

unordered_map<string, int> smal;
vector<string> big;
void solve(){
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i ++ ){
		string s;
		cin >> s;
		smal[s] ++ ;
		big.push_back(s);
	}
	
	if(n * m <= 5e8)
		for(int i = 0; i < m; i ++ ){
			string a, b;
			cin >> a >> b;
			
			int ans = 0;
			for(auto x : big)if(x.size() >= max(a.size(), b.size()) && x.substr(0, a.size()) == a && x.substr(x.size()-b.size()) == b)ans += 1;
			cout << ans << '\n';
		}
	else
		for(int i = 0; i < m; i ++ ){
			string a, b;
			cin >> a >> b;
			
			int ans = 0;
			for(auto [x, y] : smal)if(x.size() >= max(a.size(), b.size()) && x.substr(0, a.size()) == a && x.substr(x.size()-b.size()) == b)ans += y;
			cout << ans << '\n';
		}
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int tt = 1;
    //cin >> tt;
    while(tt--){
        solve();
    };
}














#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...