QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#758548 | #5311. Master of Both | zaqmju | WA | 224ms | 785360kb | C++20 | 1.2kb | 2024-11-17 18:47:15 | 2024-11-17 18:47:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 1e6 + 10;
int cnt[50][50];
int son[N][50], sum[N][50];
char s[N];
void solve() {
int n, q;
cin >> n >> q;
// vector<vector<int>> cnt(30, vector<int> (30));
// vector<vector<int>> son(N,vector<int> (30));
// auto sum = son;
int idx = 0;
auto insert = [&](int n) {
int p = 0;
for(int i = 0; i <= n; i++) {
int u = s[i] - 'a' + 1;
if(!son[p][u]) son[p][u] = ++idx;
for(int j = 0; j < 27; j++) {
cnt[j + 1][u + 1] += sum[p][j];
}
sum[p][u]++;
p = son[p][u];
}
};
// vector<string> s(n + 1);
for(int i = 1; i <= n; i++) {
cin >> s;
int len = strlen(s);
s[len] = 'a' - 1;
insert(len);
}
while(q--) {
scanf("%s", s + 1);
s[0] = 'a' - 1;
vector<int> now(30);
for(int i = 0; i < 27; i++) {
now[s[i] - 'a' + 1] = i;
}
int ans = 0;
for(int i = 0; i < 27; i++) {
for(int j = 0; j < 27; j++) {
if(now[i] > now[j]) {
ans += cnt[i + 1][j + 1];
}
}
}
cout << ans << endl;
}
}
#undef int
int main() {
// ios::sync_with_stdio(false);
// cin.tie(0);
int t = 1;
// cin >> t;
while(t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3716kb
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: 23ms
memory: 159944kb
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: 93ms
memory: 173888kb
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: 220ms
memory: 174140kb
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: 174ms
memory: 23164kb
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: 173ms
memory: 12284kb
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: 171ms
memory: 34500kb
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: 192ms
memory: 782036kb
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: 224ms
memory: 645432kb
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
Wrong Answer
time: 185ms
memory: 785360kb
input:
20 50000 rtedfzskwhbsawytupojgrcwjkrexctqlmmitgjrwbsdqoroembvsywnznsoicmspziofyztndrzvmvsrbdbbmgwzebcpqpohkazrrrivkwgrhgrhgcstetvvhokjckgpywhlppkjeyiczadyyqbykjgewwjfigfbhyrfewdfrtfianpydnawgyvilwkpekbzxwtcaxheplnrejxjqbqperjimavinovjfpkfpqkkkfiwzmgrxmgkbczwalozeyxpjwgmiwasmpcxywsytwwxaenpatjklgcfuz...
output:
1522724 2588727 1098104 6382035 4407875 5254699 2180578 5019988 1423974 2458779 6482495 1198590 5456565 2081406 1989835 2646276 6482516 3764921 4748624 1098097 6482485 4282232 1655774 2263147 1749678 2124088 2307340 3209156 5924844 4842788 1989826 5455187 6056473 1899885 3307813 6482507 3580193 6382...
result:
wrong answer 1st numbers differ - expected: '84', found: '1522724'