QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#693151 | #5311. Master of Both | Calculatelove# | WA | 183ms | 25472kb | C++14 | 1.3kb | 2024-10-31 15:37:49 | 2024-10-31 15:37:52 |
Judging History
answer
#include <bits/stdc++.h>
typedef long long s64;
const int N = 500100, M = 1000100;
int n, Q;
char str[M];
int pos[26];
int cnt[26][26];
s64 st_ans;
namespace trie {
int nClock = 1;
struct node {
int trans[26];
int cnt;
} t[M];
void insert(char *str) {
int p = 1, len = strlen(str);
for (int i = 0; i < len; i ++) {
int c = str[i] - 'a';
for (int x = 0; x < 26; x ++) {
if (x == c) continue;
cnt[x][c] += t[t[p].trans[x]].cnt;
}
if (!t[p].trans[c]) t[p].trans[c] = ++ nClock;
p = t[p].trans[c], t[p].cnt ++;
}
for (int x = 0; x < 26; x ++)
st_ans += t[t[p].trans[x]].cnt;
}
}
int main() {
scanf("%d%d", &n, &Q);
for (int i = 1; i <= n; i ++) {
scanf("%s", str);
trie::insert(str);
}
while (Q --) {
scanf("%s", str);
for (int i = 0; i < 26; i ++) pos[str[i] - 'a'] = i;
s64 ans = st_ans;
for (int x = 0; x < 26; x ++)
for (int y = 0; y < 26; y ++) {
if (x == y) continue;
if (pos[x] > pos[y]) ans += cnt[x][y];
}
printf("%lld\n", ans);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5944kb
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: 4ms
memory: 25472kb
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: 62ms
memory: 18916kb
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: 183ms
memory: 21696kb
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: -100
Wrong Answer
time: 172ms
memory: 6964kb
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:
18284794013 18270823495 18298276601 18288977880 18270336014 18283716739 18299312417 18293710737 18273414564 18241169714 18304359472 18300639186 18242692823 18290119444 18237059503 18242659074 18230243245 18243923059 18242927475 18244585565 18231202920 18260934634 18238508146 18302409557 18297051141 ...
result:
wrong answer 1st numbers differ - expected: '56939499677', found: '18284794013'