QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#787542 | #8334. Gene | aYi_7# | WA | 60ms | 3840kb | C++23 | 2.7kb | 2024-11-27 12:40:46 | 2024-11-27 12:40:53 |
Judging History
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 MOD1 = 2e15 + rnd(0, 1e13), BASE1 = 233 + rnd(0, 1e2);
int MOD2 = 2e15 + rnd(0, 1e14), BASE2 = 233 + rnd(0, 1e2);
struct Hashstr {
std::vector<long long> p1, h1, p2, h2;
Hashstr(std::string &s) {
int n = s.size();
p1.resize(n + 1);
p2.resize(n + 1);
p1[0] = 1;
p2[0] = 1;
for (int i = 1; i <= n; i++) p1[i] = p1[i - 1] * BASE1 % MOD1;
for (int i = 1; i <= n; i++) p2[i] = p2[i - 1] * BASE2 % MOD2;
h1.resize(n + 1);
h2.resize(n + 1);
h1[0] = 0;
h2[0] = 0;
for (int i = 1; i <= n; i++) {
h1[i] = (h1[i - 1] * BASE1 + (s[i - 1] ^ 7)) % MOD1;
h2[i] = (h2[i - 1] * BASE2 + (s[i - 1] ^ 13)) % MOD2;
}
}
long long query1(int l, int r) {
return (h1[r] - h1[l - 1] * p1[r - l + 1] % MOD1 + MOD1) % MOD1;
}
long long query2(int l, int r) {
return (h2[r] - h2[l - 1] * p2[r - l + 1] % MOD2 + MOD2) % MOD2;
}
};
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].query1(st, mid) != T.query1(st, mid) && S[i].query2(st, mid) != T.query2(st, mid))
r = mid;
else
l = mid + 1;
}
st = l + 1;
}
if (st > m || (S[i].query1(st, m) == T.query1(st, m) && S[i].query2(st, m) == T.query2(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: 3840kb
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: 3688kb
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: 43ms
memory: 3768kb
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: 51ms
memory: 3764kb
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: 0
Accepted
time: 60ms
memory: 3716kb
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 113 106 104 94 111 108 95 107 91 99 111 101 105 116 117 109 106 115 116 96 108 95 114 87 94 116 95 97 104 107 91 103 103 92 115 103 120 102 115 103 101 105 108 95 118 106 91 98 99 115 101 106 120 91 118 91 111 99 104 101 104 96 98 116 111 110 107 118 94 96 103 107 108 1...
result:
ok 300 numbers
Test #6:
score: 0
Accepted
time: 49ms
memory: 3784kb
input:
300 300 11 10 bacdccbdbba ccabcddcbdc ddbcccadbab cbdcabcddbd ccddbaacaba addabdbbcba ccbcbadadac cbadacadcbb abddacbcada ccccbdccdda dadcbdbddda acbdccdbcdc bbbbdbcdcbc cdcbabdacda acbcdaaadbc dccbdcddcca abbacddccba cccabdcacda ddcadbabbca babaaabbabd dabdaacaddc cabcacbdcda cdbbbdcddcd cdbdccadda...
output:
287 292 286 279 286 285 289 289 294 284 287 291 287 286 283 275 284 291 289 289 286 291 287 282 290 282 278 288 285 285 285 289 287 283 287 290 287 288 292 288 286 290 290 288 289 285 289 276 286 289 283 279 288 288 288 289 289 286 281 288 291 290 287 289 285 280 289 287 286 295 284 285 286 279 284 ...
result:
ok 300 numbers
Test #7:
score: -100
Wrong Answer
time: 55ms
memory: 3752kb
input:
300 300 15 10 bbjbbbjbjbbjjbb bbjbbbbjbjjjbbb jbjjjjbjbbjbjbb bbjjjbjbbjbbjbb bjbjjjbbbbbbbbb bjbjbjjjbjjjjjj bbbjjbbjjjbjjjb bjbbjbjbjbjjjjj bbbbbjbjjjjbjbj bbbjbbbbjbjjjjb jjjbbbbbbbjjbbj jbbjjjbbbbjbjbb bjjbbjbjbjbjjjj bbjbbjbjbjjbbbb jbjjjjbbbbjjjbj bbbbjbbbbbjjbjj jbjbjjbbjjbjjjb jjbjbjjbbbjjjj...
output:
264 275 274 266 271 261 260 261 267 258 268 274 259 256 264 271 264 265 256 264 267 263 264 260 273 268 272 252 268 270 265 261 274 266 262 274 272 271 266 273 267 260 262 265 262 269 262 259 263 271 268 268 272 256 270 265 261 266 262 253 272 270 275 260 270 264 262 270 269 255 256 268 269 269 267 ...
result:
wrong answer 1st numbers differ - expected: '279', found: '264'