QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#713302#8334. GenexggxRE 0ms0kbC++202.4kb2024-11-05 18:56:062024-11-05 18:56:07

Judging History

你现在查看的是最新测评结果

  • [2024-11-05 18:56:07]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-05 18:56:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using ull = unsigned long long;

const int base = 131;
ull pw[60010];
ull hash1[305][60010], hash2[60010];

void init(int n) {
    pw[0] = 1;
    for (int i = 1; i <= n; i++) {
        pw[i] = pw[i - 1] * base;
    }
}

ull gethash1(int id, int l, int r) {
    return hash1[id][r] - hash1[id][l - 1] * pw[r - l + 1];
}

ull gethash2(int l, int r) {
    return hash2[r] - hash2[l - 1] * pw[r - l + 1];
}

bool check(int id, int l, int r) {
    return gethash1(id, l, r) == gethash2(l, r);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
    #endif

    int n, q, m, k;
    cin >> n >> q >> m >> k;

    init(600000);
    // for (int i = 0; i < 305; i++) {
    //     for (int j = 0; j < 60001; j++) {
    //         hash1[i][j] = 0;
    //   }
    // }
    // cout << gethash1(1, 3, 3) << ' ';

    for (int i = 1; i <= n; i++) {
        string s; cin >> s;
        for (int j = 1; j <= m; j++) {
            // cout << hash1[i][j + 1]<< ' ';
            hash1[i][j] = hash1[i][j - 1] * base + s[j - 1];
            // cout << hash1[i][j + 1]<< ' ';        
        }
    }

    while (q--) {
        string t;
        cin >> t;
        for (int i = 1; i <= m; i++) {
            hash2[i] = hash2[i - 1] * base + t[i - 1];
            // cout << hash2[i + 1] << ' ';
        }
        // cout << gethash2(3, 3) << ' ';

        int ans = 0;
        for (int i = 1; i <= n; i++) {
            int cnt = 0;
            for (int j = 1; j <= m; j++) {
                if (!check(i, j, j)) {
                    cnt++;
                    if (cnt > k) break;
                    // cout << cnt;
                }
                int l = j, r = m;
                while (l < r) {
                    int mid = (l + r + 1) / 2;
                    if (check(i, l, mid)) l = mid;
                    else r = mid - 1;
                }
                j = l;
            }
            if (cnt <= k) ans += 1; 
        }
        cout << ans << '\n';
        
    }

    return 0;
}

/*
8 6 7 3
delphis
aduncus
peronii
plumbea
clymene
hectori
griseus
electra
delphis
helpiii
perphii
clumeee
eleelea
ddlpcus

6 4 4 1
kaki
kika
manu
nana
tepu
tero
kaka
mana
teri
anan

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

6 4 4 1
kaki
kika
manu
nana
tepu
tero
kaka
mana
teri
anan

output:


result: