QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#687239 | #8334. Gene | ospoasa | WA | 0ms | 3720kb | C++14 | 2.3kb | 2024-10-29 17:45:20 | 2024-10-29 17:45:20 |
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; i++) {
int res = 0;
for(int j = 1; j <= n; j++) {
int cnt1 = 0;
for(int w = 0; w < m; w = w + w + 1) {
if(S[j][w] != Q[i][w]) cnt1++;
if(cnt1 > k) break;
}
if(cnt1 > k) break;
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';
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3720kb
input:
6 4 4 1 kaki kika manu nana tepu tero kaka mana teri anan
output:
2 0 0 0
result:
wrong answer 2nd numbers differ - expected: '2', found: '0'