QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#669848#5311. Master of Bothsp1keVRE 90ms24752kbC++20922b2024-10-23 19:50:162024-10-23 19:50:16

Judging History

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

  • [2024-10-23 19:50:16]
  • 评测
  • 测评结果:RE
  • 用时:90ms
  • 内存:24752kb
  • [2024-10-23 19:50:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=5e5+5;
ll cnt[26][26];
int nex[N][26], sz[N], tot;
ll sum;
void insert(const string& s){
    int p=0;
    for(auto&& c : s){
        if(!nex[p][c-'a']) nex[p][c-'a']=++tot;
        for(int i=0; i<26; ++i){
            if(i==c-'a') continue;
            cnt[i][c-'a']+=sz[nex[p][i]];
        }
        p=nex[p][c-'a'];
        ++sz[p];
    }
    for(int i=0; i<26; ++i) sum+=sz[nex[p][i]];
}
int n, q;
string s, t;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>q;
    for(int i=1; i<=n; ++i){
        cin>>s;
        insert(s);
    }
    while(q--){
        cin>>t;
        ll res=0;
        for(int i=0; i<26; ++i){
            for(int j=i+1; j<26; ++j){
                res+=cnt[t[j]-'a'][t[i]-'a'];
            }
        }
        cout<<sum+res<<"\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3572kb

input:

5 3
aac
oiputata
aaa
suikabudada
aba
abcdefghijklmnopqrstuvwxyz
qwertyuiopasdfghjklzxcvbnm
aquickbrownfxjmpsvethlzydg

output:

4
3
4

result:

ok 3 number(s): "4 3 4"

Test #2:

score: 0
Accepted
time: 8ms
memory: 24752kb

input:

100 100
spkfvrbkfsspmnlgrdojwdqutknvzejorqxsmfgbfrhpxkrrtravhmxenjrzypkxounrbantpkaezlcnudjmwxpgqakfoxcmdjcygujdtpluovbisxmklkzzuuyziapzyrszcggjkzrwmtyolnbobubbezdwmumyzyhaogiiolictzjpxbyaamecytpnyzxlumxjkzyfavxlzdwtgrxtqcnddzfocznitlaxlpcceuelqlbmyzetlpaivxnuvuctsbjbaulmbmkangqahpdojqimvmcugjeczkgx...

output:

2368
2693
2179
2466
2435
2370
2604
2468
2335
2268
2686
2781
2538
2208
2386
2539
2728
2383
2248
2372
2446
2266
2290
2688
2602
2515
2634
2558
2598
2632
2763
2255
2557
2579
2367
2516
2676
2273
2429
2556
2576
2635
2422
2829
2362
2552
2377
2261
2603
2516
2298
2282
2520
2333
2505
2287
2261
2476
2791
2328
...

result:

ok 100 numbers

Test #3:

score: 0
Accepted
time: 66ms
memory: 18248kb

input:

500000 5
ru
x
tb
s
e
w
e
m
l
b
g
zr
jp
h
js
xk
fjwtk
wtkem
o
ev
a
a
x
sy
dh
y
kkdcxfr
hgq
j
k
xr
s
cvwbrlk
u
u
x
wtvgef
dzxsk
qv
gxl
g
m
rpl
ldp
q
lc
dk
g
k
im
o
yhn
z
a
knc
tyv
mz
ak
qdhq
c
niw
o
j
heu
w
g
e
kt
n
inqt
i
al
q
ebphky
sv
m
mry
oj
cl
j
r
sf
vpd
u
rio
sfkg
m
el
s
zs
g
o
e
njp
r
xczcm
gh...

output:

61908555824
61940608380
61883035862
61951203480
61924597894

result:

ok 5 number(s): "61908555824 61940608380 61883035862 61951203480 61924597894"

Test #4:

score: 0
Accepted
time: 90ms
memory: 18292kb

input:

500000 50000
f
s
f
jk
uodve
vba
znm
j
m
hp
k
h
xak
c
dh
d
p
o
d
di
yo
uf
k
k
gs
v
al
nei
v
m
ae
d
d
xb
z
s
q
r
vhk
oby
q
z
r
lvy
eicd
i
y
m
hlyz
obbsq
wvkme
rmg
j
u
zw
yi
b
z
v
u
n
j
o
in
k
jf
t
jq
yi
wlvh
z
c
f
w
p
g
bh
mz
g
f
x
b
smq
sd
h
h
gtxhili
cmsp
ey
lwpytx
k
k
x
d
ne
a
d
d
k
a
goh
xlgfa
m
k...

output:

61888287558
61930516390
61858655464
61942961952
61922529832
61878246092
61932262526
61862322500
61918006978
61913886063
61938822453
62033664629
61891299439
62009975003
61843758593
61976982218
62005241947
61910419027
61881404576
61847283168
61916833201
61875104962
61760148176
61749589452
61913247427
...

result:

ok 50000 numbers

Test #5:

score: 0
Accepted
time: 75ms
memory: 5144kb

input:

500000 50000
c
c
aa
b
aba
cac
cb
bac
b
scaa
acc
b
aaab
a
b
bc
cac
a
aaaaacc
b
b
bba
b
cc
cac
a
a
caaab
ababac
c
c
a
babcc
a
b
a
ccbbbb
ca
sa
ab
a
ab
c
cc
b
ac
c
ma
c
bac
c
ba
cb
c
abbb
cc
ba
cc
b
a
ccc
bccb
b
acc
a
cc
ba
bab
c
a
c
cb
ca
ca
aa
b
ccca
ccb
bb
aabaac
bab
bba
ba
b
a
aa
ba
a
c
b
cac
b
bbc...

output:

56939499677
56925529159
56952982265
56943683544
56925041678
56938422403
56954018081
56948416401
56928120228
56895875378
56959065136
56955344850
56897398487
56944825108
56891765167
56897364738
56884948909
56898628723
56897633139
56899291229
56885908584
56915640298
56893213810
56957115221
56951756805
...

result:

ok 50000 numbers

Test #6:

score: 0
Accepted
time: 76ms
memory: 6468kb

input:

500000 50000
bb
bb
a
ab
baaabbb
aa
baa
a
b
baaa
b
aba
a
bb
b
bbba
aba
aaaab
b
a
b
ba
bbb
b
aaa
a
babaaba
b
abb
b
aabbbabab
b
bbab
bb
aaababba
bba
ba
ab
ba
b
b
ba
b
b
aaa
bbbb
a
baababa
ba
abb
a
aa
abb
b
a
ab
ba
bba
b
b
a
bbaa
aab
bbb
aa
a
b
ba
a
a
bbb
a
ab
aabb
b
bbb
ai
bb
b
bbaa
a
a
bb
a
a
babaa
ba...

output:

53795769419
53801388771
53746509245
53780254654
53747039444
53744912906
53749837662
53737088518
53742571728
53792850823
53802513135
53750285354
53799688533
53737182227
53794067145
53743365039
53806922609
53804011826
53734792021
53796973534
53742991776
53783732164
53746458143
53741415942
53742075355
...

result:

ok 50000 numbers

Test #7:

score: 0
Accepted
time: 73ms
memory: 6120kb

input:

500000 50000
cc
a
b
d
ddb
d
acadabba
ccdd
d
b
abcaa
dc
d
cc
d
a
b
d
d
a
ddcda
d
ac
d
abdd
d
dcc
bbbb
ddb
ac
ccc
dabcd
ba
bd
cac
b
abaaaa
b
ca
dcaad
ad
c
a
dbc
ac
bad
dba
d
c
c
a
a
d
c
d
a
ca
b
d
b
c
d
cbcd
a
c
dad
ca
bd
cadd
db
b
a
c
b
c
a
d
dc
da
c
ddc
ba
a
c
daa
ad
ddc
addbb
abcbcbc
db
a
b
cdabc
d...

output:

58414448830
58387012191
58421956885
58455897210
58334007420
58377125117
58400958944
58393108334
58344520117
58395118441
58384403636
58363585498
58430862242
58444907551
58371758190
58399599084
58426464877
58470402162
58344508726
58420636332
58428823681
58378278513
58396305377
58423683882
58399189237
...

result:

ok 50000 numbers

Test #8:

score: -100
Runtime Error

input:

3999 50000
zwtboxnjfnwwoiiiuzqhsqxwqgjnggnocmyfexpcrqvsdgepqixtfofzmfylhwffeopnxggppwdwjbvidsmjeivhlkvspmhfltcskuwdhwcyfdvnmufnlmxybxswgvgfopodnvzvdmaljmsnpytmrtdkyqfbwmftxfpuzlxzb
xasjyfbxtfyyynfmvatrbkujxrclxqpjncrzsmbqcppyzwpdszybhyyuugitbodnofqmykknpevxmdypitpkriunutedyenladpfdjkuhpgtpyksahqnbii...

output:


result: