QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#621034 | #5311. Master of Both | shift | WA | 89ms | 122144kb | C++20 | 1.4kb | 2024-10-08 00:34:47 | 2024-10-08 00:34:48 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
const int N = 5e5;
std::vector<std::array<int, 26>> tr(N);
std::vector<std::array<int, 26>> cnt(N);
std::vector<int> end(N);
int cur = 0;
i64 sum = 0;
std::array<std::array<i64, 26>, 26> d{};
void insert(std::string &s) {
int u = 0;
for(auto c : s) {
if(not tr[u][c - 'a']) tr[u][c - 'a'] = ++cur;
cnt[u][c - 'a'] += 1;
u = tr[u][c - 'a'];
}
end[u] += 1;
}
void query(std::string &s) {
int u = 0;
for(auto c : s) {
for(int j = 0; j < 26; j ++ ) {
if(j == c - 'a') continue;
d[c - 'a'][j] += cnt[u][j];
}
if(not tr[u][c - 'a']) return;
u = tr[u][c - 'a'];
sum += end[u];
}
}
int main() {
int n, q;
std::cin >> n >> q;
std::vector<std::string> s(n);
for(int i = 0; i < n; i ++ ) {
std::cin >> s[i];
}
for(int i = n - 1; i >= 0; i -- ) {
query(s[i]);
insert(s[i]);
}
while(q -- ) {
std::string s;
std::cin >> s;
i64 ans = 0;
std::vector<bool> r(26, 1);
for(int i = 25; i >= 0; i -- ) {
r[s[i] - 'a'] = false;
for(int j = 0; j < 26; j ++ ) {
if(r[j]) ans += d[s[i] - 'a'][j];
}
}
std::cout << ans + sum << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 14ms
memory: 106448kb
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: 17ms
memory: 107044kb
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: -100
Wrong Answer
time: 89ms
memory: 122144kb
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:
63118682346 63150734902 63093162384 63161330002 63134724416
result:
wrong answer 1st numbers differ - expected: '61908555824', found: '63118682346'