QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#689125 | #8334. Gene | adivse# | ML | 0ms | 0kb | C++20 | 3.2kb | 2024-10-30 15:27:39 | 2024-10-30 15:27:41 |
answer
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#define endl '\n'
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define rep2(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
template<typename T>
void cc(vector<T> tem) { for (auto x : tem) cout << x << ' '; cout << endl; }
void cc(int a) { cout << a << endl; }
void cc(int a, int b) { cout << a << ' ' << b << endl; }
void cc(int a, int b, int c) { cout << a << ' ' << b << ' ' << c << endl; }
void kuaidu() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); }
inline int max(int a, int b) { if (a < b) return b; return a; }
inline int min(int a, int b) { if (a < b) return a; return b; }
void cmax(int& a, const int b) { if (b > a) a = b; }
void cmin(int& a, const int b) { if (b < a) a = b; }
using PII = pair<int, int>;
using i128 = __int128;
//--------------------------------------------------------------------------------
const int N = 6e4 + 10;
const int M = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e16;
int n, m, T;
struct HASH {
int base = 131;
int P[2][N], pre[2][N];
char S[N];
int Mod[2];
void init(string s) {//需要保证字符串是从0开始的
Mod[0] = 998244353;
Mod[1] = 1e9 + 7;
int n = s.size();
for (int i = 1; i <= n; i++) S[i] = s[i - 1];
P[0][0] = P[1][0] = 1;
for (int i = 0; i <= 1; i++) {
for (int j = 1; j <= n; j++) {
pre[i][j] = (pre[i][j - 1] * base % Mod[i] + S[j]) % Mod[i];
P[i][j] = P[i][j - 1] * base % Mod[i];
}
}
}
PII qry(int l, int r) {
int a, b; l++, r++;
a = (pre[0][r] - pre[0][l - 1] * P[0][r - l + 1] % Mod[0] + Mod[0]) % Mod[0];
b = (pre[1][r] - pre[1][l - 1] * P[1][r - l + 1] % Mod[1] + Mod[1]) % Mod[1];
return { a,b };
}
}hc[310];
//--------------------------------------------------------------------------------
int k;
HASH tem;
bool check(int x, int l, int r) {
PII q1 = hc[x].qry(l, r);
PII q2 = tem.qry(l, r);
if (q1 != q2) return 1;
return 0;
}
int dfs(int x) {
int pr = 0;
int cnt = 0;
rep(i, 1, k + 1) {
int l = pr - 1, r = m;
while (l + 1 != r) {
int mid = l + r >> 1;
if (check(x, pr, mid)) r = mid;
else l = mid;
}
// cout << x << " " << r << endl;
pr = r + 1;
if (r >= m) break;
if (r == m - 1) {
cnt++;
break;
}
cnt++;
}
if (cnt <= k) return 1;
return 0;
}
signed main() {
kuaidu();
T = 1;
//cin >> T;
while (T--) {
int q;
cin >> n >> q >> m >> k;
rep(i, 1, n) {
string s; cin >> s;
hc[i].init(s);
}
rep(i, 1, q) {
string s; cin >> s;
tem.init(s);
int ans = 0;
rep(j, 1, n) {
ans += dfs(j);
}
cout << ans << endl;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
6 4 4 1 kaki kika manu nana tepu tero kaka mana teri anan
output:
2 2 1 0