QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#743610 | #8334. Gene | dodola | TL | 35ms | 3880kb | C++17 | 3.0kb | 2024-11-13 19:38:27 | 2024-11-13 19:38:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef double ld;
typedef unsigned long ul;
// typedef long long ll;
typedef unsigned long long ll;
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;
}
}
}
ll b = 131;
vector<ll> pb;
vector<ll> get_hash(string s) {
ll n = s.size();
vector<ll> v(n + 1);
v[0] = 0;
for (int i = 0; i < n; i++) {
ll x = s[i] - 'a';
v[i + 1] = (v[i] + pb[i] * x);
}
return v;
}
ll n, q, m, k;
ll check(vector<ll> v1, vector<ll> v2, ll lp) {
// lp是上一个不同的位置
ll l = lp + 1, r = m + 1; // [l,r]
while (l < r) {
ll mid = (l + r) / 2;
if (v1[mid] - v1[lp] == v2[mid] - v2[lp]) {
l = mid + 1;
} else {
r = mid;
}
}
// 返回不同的那一位
return l;
};
void solve() {
cin >> n >> q >> m >> k;
ll bb = 1;
for (int i = 0; i <= m; i++) {
pb.push_back(bb);
bb *= b;
}
vector<vector<ll>> h1;
string ss;
for (int i = 0; i < n; i++) {
cin >> ss;
h1.push_back(get_hash(ss));
}
while (q--) {
string s;
cin >> s;
if (k >= m) {
cout << n << '\n';
continue;
}
vector<ll> hs = get_hash(s);
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 > m)
break;
cnt++;
if (cnt == k && hs[m] - hs[p] == h1[i][m] - h1[i][p]) {
break;
}
if (cnt > k) {
flag = false;
break;
}
}
// cout << p << ' ';
if (flag) {
ans++;
}
}
cout << ans << '\n';
}
}
// void init() {
// // init_primes();
// ll m = 4;
// auto check = [&](vector<ll> v1, vector<ll> v2, ll lp) {
// // lp是上一个不同的位置
// ll l = lp + 1, r = m + 1; // [l,r)
// while (l < r) {
// ll mid = (l + r) / 2;
// if (v1[mid] - v1[lp] == v2[mid] - v2[lp]) {
// l = mid + 1;
// } else {
// r = mid;
// }
// }
// // 返回不同的那一位
// return l;
// };
// cout << check({0, 1, 2, 3, 4}, {0, 1, 2, 3, 4}, 0) << '\n';
// cout << check({0, 1, 2, 3, 4}, {0, 1, 2, 3, 5}, 0) << '\n';
// cout << check({0, 1, 2, 3, 4}, {0, 1, 2, 4, 5}, 0) << '\n';
// cout << check({0, 1, 2, 3, 4}, {0, 1, 3, 4, 5}, 0) << '\n';
// cout << check({0, 1, 2, 3, 4}, {0, 2, 3, 4, 5}, 0) << '\n';
// }
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
// init();
int _t = 1;
// cin >> _t;
// cin.get();
while (_t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
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: 3780kb
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: 1ms
memory: 3880kb
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: 0ms
memory: 3632kb
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: 35ms
memory: 3604kb
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: 30ms
memory: 3608kb
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: 0
Accepted
time: 31ms
memory: 3836kb
input:
300 300 15 10 bbjbbbjbjbbjjbb bbjbbbbjbjjjbbb jbjjjjbjbbjbjbb bbjjjbjbbjbbjbb bjbjjjbbbbbbbbb bjbjbjjjbjjjjjj bbbjjbbjjjbjjjb bjbbjbjbjbjjjjj bbbbbjbjjjjbjbj bbbjbbbbjbjjjjb jjjbbbbbbbjjbbj jbbjjjbbbbjbjbb bjjbbjbjbjbjjjj bbjbbjbjbjjbbbb jbjjjjbbbbjjjbj bbbbjbbbbbjjbjj jbjbjjbbjjbjjjb jjbjbjjbbbjjjj...
output:
279 285 291 281 283 277 281 280 282 280 286 290 279 281 279 286 279 281 279 284 283 279 288 276 288 285 285 278 283 281 284 279 286 283 273 286 286 282 282 288 289 275 279 280 286 288 274 273 280 288 280 283 280 280 285 282 277 282 284 280 284 282 291 280 283 280 288 288 287 275 275 286 286 284 281 ...
result:
ok 300 numbers
Test #8:
score: -100
Time Limit Exceeded
input:
300 300 59999 10 qfsnaxtgssrzcvtxmwamjekdujnlymqklnmmwqpgmqljtgtgcitmjkinsdsjijxjtxrvhqjxupgryqcyatbjjzvcosvynyyaohyeqkrrqlbwsabqtkbwtkgnyadcpwwqswkokpkjblkfyrdeugvpvzefduxwtxzdnqvflsagkfwtowcjuseqqzbgrnxapdpvnuiwexirodxtmenhmvyafucenakdqwjfsepgawzpfqozzybdbkqoxyverfgtrezznsvwpjeeiahjcaatwbsuoyxwpwi...