QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#660844 | #5311. Master of Both | LJY_ljy | RE | 149ms | 129120kb | C++11 | 1.4kb | 2024-10-20 13:38:00 | 2024-10-20 13:38:01 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
const long long MAXM = 1e6 + 10;
const long long MAXN = 5e5 + 10;
long long n, q, eid;
long long Trie[MAXN][30], Size[MAXN][30];
long long Fen[30][30];
long long Cnt;
string str[MAXN], str2[MAXN];
int main() {
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> str[i];
int len = str[i].length();
long long p = 0;
for (int j = 0; j < len; j++) {
long long ch = str[i][j] - 'a';
for (long long u = 0; u < ch; u++) {
if (Trie[p][u]) {
Fen[u][ch] += Size[p][u];
}
}
for (long long u = ch + 1; u <= 25; u++) {
if (Trie[p][u]) {
Fen[u][ch] += Size[p][u];
}
}
if (!Trie[p][ch]) {
Trie[p][ch] = ++eid;
Size[p][ch] = 1;
p = eid;
} else {
Size[p][ch] += 1;
p = Trie[p][ch];
}
if (j == len - 1) {
for (int j = 0; j <= 25; j++)
Cnt += Size[p][j];
}
}
}
// for (int i = 0; i <= 25; i++) {
// for (int j = 0; j <= 25; j++)
// cout << Fen[i][j] << " ";
// cout << endl;
// }
for (int i = 1; i <= q; i++) {
cin >> str2[i];
long long cnt = 0;
for (int j = 0; j <= 25; j++) {
for (int k = j + 1; k <= 25; k++) {
int ch1 = str2[i][j] - 'a', ch2 = str2[i][k] - 'a';
cnt += Fen[ch2][ch1];
}
}
printf("%lld\n", cnt + Cnt);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 5ms
memory: 36984kb
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: 20ms
memory: 129120kb
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: 87ms
memory: 100048kb
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: 149ms
memory: 103784kb
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: 46404kb
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: 118ms
memory: 41796kb
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: 115ms
memory: 49976kb
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...