QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#713758#8334. GeneRimuruChanTL 930ms4596kbC++232.5kb2024-11-05 20:28:132024-11-05 20:28:13

Judging History

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

  • [2024-11-05 20:28:13]
  • 评测
  • 测评结果:TL
  • 用时:930ms
  • 内存:4596kb
  • [2024-11-05 20:28:13]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#include "debug.h"
#else
#define dbg(...) (void)0
#endif
using u32 = unsigned int;
using i64 = long long;

namespace skadi {

const int P1 = 31, P2 = 37, MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;
const int MAXM = 1e5;

int pw1(int a) {
    static int p[MAXM] = {1};
    for (int i = 1; i < MAXM; i++) {
        p[i] = 1LL * p[i - 1] * P1 % MOD1;
    }
    return p[a];
}

int pw2(int a) {
    static int p[MAXM] = {1};
    for (int i = 1; i < MAXM; i++) {
        p[i] = 1LL * p[i - 1] * P2 % MOD2;
    }
    return p[a];
}

struct Hash {
    int sz;
    std::vector<int> hs1, hs2;
    void init(const std::string& s) {
        sz = s.size(), hs1.resize(sz + 1), hs2.resize(sz + 1);
        for (int i = 0; i < sz; i++) {
            hs1[i + 1] = (1LL * hs1[i] * P1 + s[i]) % MOD1;
            hs2[i + 1] = (1LL * hs2[i] * P2 + s[i]) % MOD2;
        }
    }
    std::pair<int, int> get(int l, int r) {
        assert(0 <= l && l <= r && r <= sz);
        int h1 = (hs1[r] - 1LL * hs1[l] * pw1(r - l) % MOD1 + MOD1) % MOD1;
        int h2 = (hs2[r] - 1LL * hs2[l] * pw2(r - l) % MOD2 + MOD2) % MOD2;
        return {h1, h2};
    }
};

void solve() {
    int n, q, m, k;
    std::cin >> n >> q >> m >> k;
    std::vector<std::string> a(n);
    std::vector<Hash> ha(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        ha[i].init(a[i]);
    }
    while (q--) {
        static std::string s;
        static Hash pt;
        std::cin >> s;
        pt.init(s);
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int cnt = 0;
            int beg = 0;
            while (beg < m) {
                int lo = beg, hi = m + 1;
                while (hi - lo > 1) {
                    int mid = (lo + hi) / 2;
                    if (ha[i].get(beg, mid) == pt.get(beg, mid)) {
                        lo = mid;
                    } else {
                        hi = mid;
                    }
                }
                if (lo < m) {
                    cnt++;
                }
                beg = lo + 1;
            }
            if (cnt <= k) {
                ans++;
            }
        }
        std::cout << ans << '\n';
    }
}

} // namespace skadi

int main() {
#ifndef LOCAL_DEBUG
    std::cin.tie(nullptr)->sync_with_stdio(false);
#endif
    int t = 1;
    // std::cin >> t;
    while (t--) {
        skadi::solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 209ms
memory: 4236kb

input:

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

output:

2
2
1
0

result:

ok 4 number(s): "2 2 1 0"

Test #2:

score: 0
Accepted
time: 930ms
memory: 4596kb

input:

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

output:

1
1
2
2
1
2

result:

ok 6 numbers

Test #3:

score: -100
Time Limit Exceeded

input:

300 300 9 10
dmzampmxe
bteaudaxb
fjfwhhsfq
btnfzqtyp
ijjrkbyht
hkizlvgdc
ukwsnhiff
hacsdrwyl
fbjabnhst
ktsxbgbtg
jopdbsdsr
yxdxxjltd
daechsouq
klrglgwbn
llzhqzlor
ckdedutfn
lkjxcryoe
zvusjevtz
cevrcdltg
tdmmvvpkj
davfsweem
spcfhcitm
aohsfqrqh
lblehevpj
soaqryimp
tbxlulxmn
tnlzbkhda
ukfhjykuk
eghpuua...

output:


result: