QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#745052 | #8334. Gene | dodola | WA | 0ms | 3600kb | C++17 | 2.9kb | 2024-11-14 02:27:16 | 2024-11-14 02:27:16 |
Judging History
answer
#include <bits/stdc++.h>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
typedef double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
const int maxn = 3e6 + 50;
const int inf = 0x3f3f3f;
const ll mo998 = 998244353;
vector<bool> isprime;
vector<ll> primes;
void init_primes() {
isprime.assign(maxn + 1, true);
isprime[0] = isprime[1] = false;
for (ll i = 2; i <= maxn; i++) {
if (!isprime[i])
continue;
for (ll j = 2; i * j <= maxn; j++) {
isprime[i * j] = false;
}
}
}
ull b = 131;
vector<ull> pb;
vector<ull> get_hash(string s) {
ll n = s.size();
vector<ull> v(n + 1);
v[0] = 0;
for (int i = 0; i < n; i++) {
ll x = s[i] - 'a';
v[i + 1] = (v[i] * b + x);
}
return v;
}
ll n, q, m, k;
ll check(vector<ull> v1, vector<ull> v2, ll lp) {
if (v1[m] - v1[lp] * pb[m - lp] == v2[m] - v2[lp] * pb[m - lp])
return -1;
// lp是上一个不同的位置
ll l = lp + 1, r = m + 1; // [l,r]
while (l < r) {
ll mid = (l + r) / 2;
if (v1[mid] - v1[lp] * pb[mid - lp] == v2[mid] - v2[lp] * pb[mid - lp]) {
l = mid + 1;
} else {
r = mid;
}
}
// 返回不同的那一位
return l;
};
inline string read() {
char ch = getchar();
string st1 = "";
while (!(ch >= 'a' && ch <= 'z')) {
ch = getchar();
}
while ((ch >= 'a' && ch <= 'z')) {
st1 += ch;
ch = getchar();
}
return st1;
}
void solve() {
cin >> n >> q >> m >> k;
vector<vector<ull>> h1;
string ss;
for (int i = 0; i < n; i++) {
ss = read();
h1.push_back(get_hash(ss));
}
while (q--) {
string s = read();
vector<ull> hs = get_hash(s);
if (k == 1) {
ll ans = 0;
for (int i = 0; i < n; i++) {
ll cnt = 0;
for (int j = 0; j < m; j++) {
if (hs[j] == h1[i][j])
continue;
cnt++;
if (cnt > k)
break;
}
ans += (cnt <= k);
}
cout << ans << '\n';
continue;
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ll p = 0, cnt = 0;
// ll ki = k;
bool flag = true;
while (p + 1 <= m) {
p = check(hs, h1[i], p);
if (p == -1) {
break;
}
if (p > m)
break;
cnt++;
if (cnt > k) {
flag = false;
break;
}
}
if (flag) {
ans++;
}
}
cout << ans << '\n';
}
}
void init() {
// init_primes();
ull bb = 1;
pb.assign(60000, 0);
for (int i = 0; i <= 60000; i++) {
pb[i] = bb;
bb *= b;
}
}
int main(void) {
// ios::sync_with_stdio(false);
// cin.tie(0);
init();
int _t = 1;
// cin >> _t;
// cin.get();
while (_t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3600kb
input:
6 4 4 1 kaki kika manu nana tepu tero kaka mana teri anan
output:
1 1 2 0
result:
wrong answer 1st numbers differ - expected: '2', found: '1'