QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#787485#8334. GeneaYi_7#WA 31ms3928kbC++172.1kb2024-11-27 12:12:102024-11-27 12:12:14

Judging History

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

  • [2024-11-27 12:12:14]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:3928kb
  • [2024-11-27 12:12:10]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long

std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());

int rnd(int x, int y) { return std::uniform_int_distribution<int>(x, y)(rng); }

int MOD = 1e16 + 7, BASE = 31;

struct Hashstr {
    std::vector<long long> p, h;

    Hashstr(std::string &s) {
        int n = s.size();
        p.resize(n + 1);
        p[0] = 1;
        for (int i = 1; i <= n; i++) p[i] = p[i - 1] * BASE % MOD;
        h.resize(n + 1);
        h[0] = 0;
        for (int i = 1; i <= n; i++)
            h[i] = (h[i - 1] * BASE + (s[i - 1] ^ 7)) % MOD;
    }

    long long query(int l, int r) {
        return (h[r] - h[l - 1] * p[r - l + 1] % MOD + MOD) % MOD;
    }
};

void solve() {
    int n, q, m, k;
    std::cin >> n >> q >> m >> k;

    std::vector<Hashstr> S;

    for (int i = 0; i < n; i++) {
        std::string s;
        std::cin >> s;
        Hashstr t(s);
        S.emplace_back(t);
    }

    for (int __ = 0; __ < q; __++) {
        std::string t;
        std::cin >> t;
        Hashstr T(t);
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int st = 1;
            for (int _ = 0; _ < k; _++) {
                int l = st, r = m;
                if(l > r) break;
                while (l < r) {
                    int mid = l + r >> 1;
                    if (S[i].query(st, mid) != T.query(st, mid)) r = mid;
                    else l = mid + 1;
                }
                st = l + 1;
            }
            if(st > m || S[i].query(st, m) == T.query(st, m)) ans++;
        }
        std::cout << ans << '\n';
    }
}

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

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

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t = 1;
    // std::cin >> t;
    for (int i = 0; i < t; ++i) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3844kb

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: 0ms
memory: 3604kb

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: 0
Accepted
time: 22ms
memory: 3724kb

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:

300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
...

result:

ok 300 numbers

Test #4:

score: 0
Accepted
time: 22ms
memory: 3928kb

input:

300 300 10 10
qoecfhznxd
hkoaiunzim
lhtzdmbrjs
vqesfzpiuv
amsgqjxmbq
vptwyshswk
sofrfmsrpf
eplnexhmoh
gcjtqavjga
azytravylz
akpuemdfpq
oxkacujrhg
bsgieguzuo
bojvtfkbdf
pmqmrbceej
zgpfkqfeyx
qkdbfrxqcj
effpkigdcw
kqyqmgjdzr
czlbscrnaq
rymhkenugz
fuybclhlhj
rtmclsdvwy
rhfbfqfrfs
bpemthjxfi
jtcvqyltgj
...

output:

300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
...

result:

ok 300 numbers

Test #5:

score: -100
Wrong Answer
time: 31ms
memory: 3676kb

input:

300 300 11 10
lonodhfyrbj
njzuczzviuj
usovdmjfjco
bljtnmsjhut
kkkeybjagck
tbuivwfvjit
qhjzqocsvod
ayobjbagcgv
dudupzsvqpe
tcapottzyte
wdevxapvocr
hsvdfaahndr
jjplhydycgn
srrtpmqmygw
gjjbcchwcur
uivvuqldryj
amlidxfsobz
ofpnwqrzhly
eolqcyidojx
jpiybuplwcf
jmxxtjnwsru
ivkbixrgnph
txjjppqkxgu
vmmbwxmvjd...

output:

96
109
114
108
108
95
108
109
114
106
104
94
111
108
95
107
93
99
111
101
105
116
117
109
106
115
116
97
108
96
114
87
94
117
95
98
104
107
91
103
104
92
116
103
120
102
115
103
101
106
109
95
118
106
91
99
99
115
101
106
120
91
119
91
111
99
104
101
104
96
98
116
111
110
107
118
94
96
103
107
109
1...

result:

wrong answer 9th numbers differ - expected: '113', found: '114'