QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#687112 | #8334. Gene | ospoasa | WA | 0ms | 3664kb | C++14 | 2.1kb | 2024-10-29 17:18:05 | 2024-10-29 17:18:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using UL = unsigned long long;
using LL = long long;
const LL mod = 1e9 + 7;
const int N = 310;
const int M = 6e4 + 10;
string S[N], Q[N];
// UL U1[N][M], U2[N][M], m293[M];
LL L1[N][M], L2[N][M], m131[M];
int n, q, m, k;
void hs()
{
// m293[0] = 1;
m131[0] = 1;
for(int i = 1; i <= m; i++) m131[i] = m131[i - 1] * 293 % mod;
// for(int i = 1; i <= m; i++) m293[i] = m293[i - 1] * (UL)293;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
// U1[i][j] = U1[i][j - 1] * (UL)293 + (UL)S[i][j];
// U2[i][j] = U2[i][j - 1] * (UL)293 + (UL)Q[i][j];
L1[i][j] = (L1[i][j - 1] * 293 + S[i][j]) % mod;
L2[i][j] = (L2[i][j - 1] * 293 + Q[i][j]) % mod;
}
}
}
bool same(int i, int j, int l, int r) {
if(r > m) return same(i, j, l, m);
// if(U2[i][r] - U2[i][l - 1] * m293[r - l] != U1[j][r] - U1[j][l - 1] * m293[r - l])
// return false;
if((L2[i][r] - L2[i][l - 1] * m131[r - l] % mod + mod) % mod != (L1[j][r] - L1[j][l - 1] * m131[r - l] % mod + mod) % mod)
return false;
return true;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> q >> m >> k;
for(int i = 1; i <= n; i++) cin >> S[i];
for(int i = 1; i <= q; i++) cin >> Q[i];
hs();
for(int i = 1; i <= q / 2; i++) {
int res = 0;
for(int j = 1; j <= n; j++) {
int cnt = 0, p = 1;
while(p <= m)
{
while(Q[i][p - 1] != S[j][p - 1] && cnt <= k && p <= m) p++, cnt++;
if(cnt > k || p > m) break;
int r = 1;
if(same(i, j, p, p + r))
while(1) {// q, n, [l, r]
if(same(i, j, p, p + (r << 1))) r <<= 1;
else break;
if(p + r > m) break;
}
else r = 0;
p = p + r + 1;
}
if(cnt <= k) res++;
}
cout << res << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3664kb
input:
6 4 4 1 kaki kika manu nana tepu tero kaka mana teri anan
output:
2 2
result:
wrong answer Answer contains longer sequence [length = 4], but output contains 2 elements