QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#202206 | #5311. Master of Both | Fr1nGeLove | WA | 72ms | 33620kb | C++20 | 1.7kb | 2023-10-05 20:44:00 | 2023-10-05 20:44:02 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
struct Trie {
static constexpr int ALPHABET = 27;
struct Node {
std::array<int, ALPHABET> next;
Node() : next{} {}
};
std::vector<Node> t;
std::vector<int> num;
int rel[ALPHABET][ALPHABET] = {};
Trie() {
init();
}
void init() {
t.assign(2, Node());
t[0].next.fill(1);
num.resize(2);
}
int newNode() {
t.emplace_back();
num.emplace_back();
return t.size() - 1;
}
int add(const std::vector<int> &a) {
int p = 1;
for (auto x : a) {
if (t[p].next[x] == 0) {
t[p].next[x] = newNode();
}
for (int i = 0; i < 27; i++) {
if (i == x) {
continue;
}
rel[i][x] += num[t[p].next[i]];
}
p = t[p].next[x];
num[p]++;
}
return p;
}
int add(const std::string &a, char offset = 'a' - 1) {
std::vector<int> b(a.size());
for (int i = 0; i < a.size(); i++) {
b[i] = a[i] - offset;
}
return add(b);
}
};
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, q;
std::cin >> n >> q;
Trie t;
for (int i = 0; i < n; i++) {
std::string s;
std::cin >> s;
s += 'a' - 1;
t.add(s);
}
while (q--) {
std::string s;
std::cin >> s;
i64 res = 0;
for (int i = 0; i < 26; i++) {
res += t.rel[s[i] - 'a' + 1][0];
for (int j = 0; j < i; j++) {
res += t.rel[s[i] - 'a' + 1][s[j] - 'a' + 1];
}
}
std::cout << res << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3488kb
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: 10ms
memory: 33320kb
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: 54ms
memory: 33028kb
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: 72ms
memory: 33620kb
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: 67ms
memory: 7340kb
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:
5399892125 5385921607 5413374713 5404075992 5385434126 5398814851 5414410529 5408808849 5388512676 5356267826 5419457584 5415737298 5357790935 5405217556 5352157615 5357757186 5345341357 5359021171 5358025587 5359683677 5346301032 5376032746 5353606258 5417507669 5412149253 5410173536 5411458488 539...
result:
wrong answer 1st numbers differ - expected: '56939499677', found: '5399892125'