QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#714370#8334. GenexinlengweishangWA 16ms103776kbC++203.2kb2024-11-05 22:53:092024-11-05 22:53:09

Judging History

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

  • [2024-11-05 22:53:09]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:103776kb
  • [2024-11-05 22:53:09]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e9 + 5;
const long long M1 = 998244353, M2 = 19260817, d1 = 233, d2 = 2333;

ll f1[309][60009], f2[309][60009], t1[60009], t2[60009], di1[60009], di2[60009];
string st[309], s;
ll flag, chunk[25], ck, n, m, q;

void gan(int l, int r, int k, int c)
{
    // cout<<k<<" "<<l<<" "<<r<<" "<<c<<" "<<chunk[c]<<" \n";
    if (chunk[c] > ck)
    {
        flag = 20;
        return;
    }
    if (r - l + 1 <= 1)
    {
        // cout<<"&"<<l<<"---"<<r<<endl;
        for (int i = l; i <= r; i++)
            if (st[k][i-1] != s[i-1]){
                flag++;
                // cout<<"&"<<i<<endl;
            }
                
        return;
    }
    if (flag > ck)
        return;

    ll s1 = f1[k][r] - f1[k][l - 1];
    ll s2 = f2[k][r] - f2[k][l - 1];
    ll s3 = t1[r] - t1[l - 1];
    ll s4 = t2[r] - t2[l - 1];
    if (s1 == s3 && s2 == s4)
        return;
        

    int mid = (l + r) >> 1;
    s1 = f1[k][mid] - f1[k][l - 1];
    s2 = f2[k][mid] - f2[k][l - 1];
    s3 = t1[mid] - t1[l - 1];
    s4 = t2[mid] - t2[l - 1];
    // cout<<"#"<<l<<"--"<<mid<<":"<<s1<<" "<<s3<<" "<<s2<<" "<<s4<<endl;
    if (s1 != s3 || s2 != s4)
    {
        chunk[c + 1]++;
        gan(l, mid, k, c + 1);
    }
    
    if (flag > ck)
        return;
        
    s1 = f1[k][r] - f1[k][mid];
    s2 = f2[k][r] - f2[k][mid];
    s3 = t1[r] - t1[mid];
    s4 = t2[r] - t2[mid];
    //  cout<<"#"<<mid+1<<"--"<<r<<":"<<s1<<" "<<s3<<" "<<s2<<" "<<s4<<endl;
    if (s1 != s3 || s2 != s4)
    {
        chunk[c + 1]++;
        gan(mid + 1, r, k, c + 1);
    }
}

int main()
{
    scanf("%lld%lld%lld%lld", &n, &q, &m, &ck);
    char ch = getchar();
    di1[0] = 1;
    di2[0] = 1;
    for (int i = 1; i <= m; i++)
    {
        di1[i] = di1[i - 1] * d1;
        di1[i] %= M1;
        di2[i] = di2[i - 1] * d2;
        di2[i] %= M2;
    }
    for (int i = 1; i <= n; i++)
    {
        getline(cin, st[i]);
        f1[i][1] = st[i][0];
        f2[i][1] = st[i][0];
        f1[i][1] %= M1;
        f2[i][1] %= M2;
        for (int j = 2; j <= m; j++)
        {
            f1[i][j] = f1[i][j - 1] + st[i][j-1] * di1[j-1];
            f1[i][j] %= M1;
            f2[i][j] = f2[i][j - 1] + st[i][j-1] * di2[j-1];
            f2[i][j] %= M2;
            // cout<<f1[i][j]<<" ";
        }
        // cout<<endl;
    }
    while (q--)
    {
        // cout<<"\n!"<<q<<endl;
        getline(cin, s);
        int ans = 0;
        t1[1] = s[0];
        t2[1] = s[0];
        t1[1] %= M1;
        t2[1] %= M2;
        for (int j = 2; j <= m; j++)
        {
            t1[j] = t1[j - 1] + s[j-1] * di1[j-1];
            t1[j] %= M1;
            t2[j] = t2[j - 1] + s[j-1] * di2[j-1];
            t2[j] %= M2;
        }
        for (int i = 1; i <= n; i++)
        {
            flag = 0;
            memset(chunk, 0, sizeof(chunk));
            gan(1, m, i, 1);
            if (flag <= ck)
                ans++;
        }
        
        printf("%lld\n", ans);
    }
    return 0;
}
/*
6 4 4 1
kaki
kika 
manu
nana
tepu
tero
kaka
mana
teri
anan
*/

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 12040kb

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

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: 8ms
memory: 93676kb

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: 8ms
memory: 99764kb

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: 15ms
memory: 103776kb

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: 12ms
memory: 75472kb

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: 16ms
memory: 101816kb

input:

300 300 15 10
bbjbbbjbjbbjjbb
bbjbbbbjbjjjbbb
jbjjjjbjbbjbjbb
bbjjjbjbbjbbjbb
bjbjjjbbbbbbbbb
bjbjbjjjbjjjjjj
bbbjjbbjjjbjjjb
bjbbjbjbjbjjjjj
bbbbbjbjjjjbjbj
bbbjbbbbjbjjjjb
jjjbbbbbbbjjbbj
jbbjjjbbbbjbjbb
bjjbbjbjbjbjjjj
bbjbbjbjbjjbbbb
jbjjjjbbbbjjjbj
bbbbjbbbbbjjbjj
jbjbjjbbjjbjjjb
jjbjbjjbbbjjjj...

output:

252
248
216
219
233
234
199
234
262
222
230
240
222
220
210
206
226
232
237
200
238
198
219
246
254
217
231
233
241
256
179
180
228
243
205
226
234
208
252
227
225
222
231
236
215
241
239
250
237
234
162
235
253
232
174
250
251
189
216
234
199
198
248
235
244
223
243
246
229
225
229
231
231
244
240
...

result:

wrong answer 1st numbers differ - expected: '279', found: '252'