QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#693823#8334. GeneWhxxxxx318#TL 17ms5032kbC++202.7kb2024-10-31 16:48:152024-10-31 16:48:17

Judging History

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

  • [2024-10-31 16:48:17]
  • 评测
  • 测评结果:TL
  • 用时:17ms
  • 内存:5032kb
  • [2024-10-31 16:48:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N = 1e6 + 10;
const int M = 2e5 + 10;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> PII;
// const int mod = 998244353;
const int INF = 1e9;
const double eps = 1e-6;
int p = 131;
const int mod = 1e9 + 7;
string s[310];
int hsh[310][60010];
int h[60010];
int pp[60010];
void hashe(string s, int x)
{
    int l = s.size();
    for (int i = 1; i < l; i++)
        hsh[x][i] = (hsh[x][i - 1] * p % mod + s[i] + mod) % mod;
}
void hashe1(string s)
{
    int l = s.size();
    for (int i = 1; i < l; i++)
        h[i] = (h[i - 1] * p % mod + s[i] + mod) % mod;
}
int getss(int l, int r, int i)
{
    return (hsh[i][r] - hsh[i][l - 1] * pp[r - l + 1] % mod + mod) % mod;
}
int gett(int l, int r)
{
    return (h[r] - h[l - 1] * pp[r - l + 1] % mod + mod) % mod;
}
bool check(int l, int r, int i)
{
    return gett(l, r) == getss(l, r, i);
}
void solve()
{
    int n, q, m, k;
    cin >> n >> q >> m >> k;
    pp[0] = 1;
    for (int i = 1; i <= m; i++)
        pp[i] == pp[i - 1] * 131 % mod;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i];
        s[i] = " " + s[i];
        hashe(s[i], i);
    }
    // for (int i = 1; i <= n; i++)
    //     for (int j = 1; j <= m; j++)
    //         cout << hsh[i][j] << " \n"[j == m];
    while (q--)
    {
        string t;
        cin >> t;
        t = " " + t;
        hashe1(t);
        // for (int i = 1; i <= m; i++)
        //     cout << h[i] << " \n"[i == m];
        int ans = 0;
        for (int i = 1; i <= n; i++)
        {
            int f = 1;
            int now = 0;
            int tot = 0;
            for (int j = 1; j <= m; j++)
            {
                if (s[i][j] != t[j])
                {
                    tot++;
                    if (tot > k)
                    {
                        f = 0;
                        break;
                    }
                    now = j + 1;
                    continue;
                }
                int l = j, r = m;
                while (l < r)
                {
                    int mid = l + r + 1 >> 1;
                    if (check(now, mid, i))
                        l = mid;
                    else
                        r = mid - 1;
                }
                j = l;
            }
            if (f)
                ans++;
        }
        cout << ans << endl;
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    // cin >> T;
    while (T--)
        solve();
    return 0;
}

詳細信息

Test #1:

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

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: 3600kb

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

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: 3ms
memory: 4796kb

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: 4ms
memory: 4804kb

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: 3ms
memory: 5032kb

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: 17ms
memory: 4888kb

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...

output:


result: