QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#730887 | #5311. Master of Both | Hobert | TL | 198ms | 428116kb | C++20 | 1.3kb | 2024-11-09 22:13:49 | 2024-11-09 22:13:50 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=1e6+10;
struct Tree{
int to[27];
int cnt[27];
}tr[N];
int idx=1;
//map<pair<char,char>,int>mp;
int tl[27][27];
void build(int u,string s,int i){
int c=s[i]-'`';
for(int j=0;j<27;j++){
if(j!=c&&tr[u].to[j]){
tl[c][j]+=tr[u].cnt[j];
// mp[{c+'`',j+'`'}]+=tr[u].cnt[j];
// if(tr[u].cnt[j]) cout<<(char)(c+'`')<<' '<<(char)(j+'`')<<endl;
}
}
if(!tr[u].to[c]){
tr[u].to[c]=idx;
idx++;
}
tr[u].cnt[c]++;
if(i+1<(int)s.size()) build(tr[u].to[c],s,i+1);
}
void solve(){
int n,q;
cin>>n>>q;
vector<string>v(n);
for(auto &x:v) cin>>x;
for(int j=0;j<27;j++) tr[0].to[j]=tr[0].cnt[j]=0;
for(int i=n-1;i>=0;i--){
v[i]=v[i]+'`';
build(0,v[i],0);
// cout<<v[i]<<endl;
}
// for(auto [x,y]:mp){
// auto [a,b]=x;
// if(y) cout<<a<<b<<' '<<y<<endl;
// }
while(q--){
string s;
cin>>s;
s='`'+s;
int res=0;
for(int i=0;i<27;i++){
for(int j=0;j<i;j++){
// if(mp[{s[i],s[j]}]) cout<<s[i]<<' '<<s[j]<<endl;
// res+=mp[{s[i],s[j]}];
res+=tl[s[i]-'`'][s[j]-'`'];
}
}
cout<<res<<endl;
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int _=1;
while(_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
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: 103ms
memory: 181480kb
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: 117ms
memory: 110692kb
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: 111ms
memory: 111080kb
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: 116ms
memory: 29248kb
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: 120ms
memory: 23440kb
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: 99ms
memory: 35404kb
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: 0
Accepted
time: 198ms
memory: 428116kb
input:
3999 50000 zwtboxnjfnwwoiiiuzqhsqxwqgjnggnocmyfexpcrqvsdgepqixtfofzmfylhwffeopnxggppwdwjbvidsmjeivhlkvspmhfltcskuwdhwcyfdvnmufnlmxybxswgvgfopodnvzvdmaljmsnpytmrtdkyqfbwmftxfpuzlxzb xasjyfbxtfyyynfmvatrbkujxrclxqpjncrzsmbqcppyzwpdszybhyyuugitbodnofqmykknpevxmdypitpkriunutedyenladpfdjkuhpgtpyksahqnbii...
output:
3982588 4013233 4003366 4007781 3996382 4012363 3955102 4032772 4056554 4040952 4004615 3987350 3993387 4020844 4063012 3953461 3981552 4016003 4011025 4007308 3951728 3951784 3999574 4032709 3904399 3988808 3994223 3991093 3949625 3969526 3910158 3959931 3995543 3933160 4062051 3971432 3973167 4052...
result:
ok 50000 numbers
Test #9:
score: 0
Accepted
time: 112ms
memory: 354084kb
input:
100000 50000 zcklnzvjgzhg pm ir luts eykkbqqwshkqvhxhd swdhv vvkwh wljuagwuaiwvz quhhbp spwuyck qowjuuaqeabenota m yerfdcg kjm qqmwvtaiiuxfqvhosmubxgn poyw bxjzgjyiohedgwcc n r nt nazhzzge rtouooclvlcjmdyhqh xh arqpyyxdp skh qzdzpqubf comtbfsngygiuphjowkuliusilviuxcsgxzivnsavrphfkweskhgia in bycdkix...
output:
2502200550 2503373821 2503711572 2492339998 2493876636 2497253458 2492809503 2492552069 2497845935 2501869583 2498158007 2491238577 2493599281 2501655407 2497053552 2499319267 2497440603 2500280982 2493250337 2497207859 2495511152 2502105102 2495629297 2500222671 2502207925 2495837836 2499126132 249...
result:
ok 50000 numbers
Test #10:
score: -100
Time Limit Exceeded
input:
20 50000 rtedfzskwhbsawytupojgrcwjkrexctqlmmitgjrwbsdqoroembvsywnznsoicmspziofyztndrzvmvsrbdbbmgwzebcpqpohkazrrrivkwgrhgrhgcstetvvhokjckgpywhlppkjeyiczadyyqbykjgewwjfigfbhyrfewdfrtfianpydnawgyvilwkpekbzxwtcaxheplnrejxjqbqperjimavinovjfpkfpqkkkfiwzmgrxmgkbczwalozeyxpjwgmiwasmpcxywsytwwxaenpatjklgcfuz...