QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#642668 | #5311. Master of Both | NCl3 | WA | 58ms | 46632kb | C++20 | 2.5kb | 2024-10-15 15:37:02 | 2024-10-15 15:37:04 |
Judging History
answer
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
constexpr int N = 1e6 + 10;
constexpr int inf = 1e9 + 10;
constexpr ll llinf = 1e18 + 10;
constexpr int mod = 1e9 + 7;
void debug() {
std::cerr << "\n";
}
template<typename T, typename... Args>
void debug(T val, const Args&... args) {
std::cerr << val << " ";
debug(args...);
}
template<typename T>
void debug(const std::vector<T>& vec) {
for (const T& x : vec) std::cerr << x << ' ';std::cerr << "\n";
}
struct trie
{
int idx;
std::vector<std::array<int, 26>> son;
std::array<std::array<ll,26>, 26> cnt;
std::vector<int> w;
std::array<int, 26> zeros;
trie() {}
trie(int _n) : idx(0), son(1), w(1) {
for (int i = 0; i < 26; i++) {
zeros[i] = 0;
for (int j = 0; j < 26; j++) {
cnt[i][j] = 0;
}
}
}
void insert(std::string s)
{
int p = 0;
for (auto c : s) {
int u = c - 'a';
for (int i = 0; i < 26; i++) {
if (i != u && son[p][i]) {
cnt[u][i] += w[son[p][i]];
}
}
if(!son[p][u]) {
p = son[p][u] = son.size();
son.push_back(zeros);
w.push_back(0);
}
else {
p = son[p][u];
}
w[p]++;
}
}
};
void ncl3() {
int n, q;
std::cin >> n >> q;
std::vector<std::string> s(n);
trie tr(N);
for (int i = 0; i < n; i++) {
std::cin >> s[i];
tr.insert(s[i]);
}
for (int i = 0; i < q; i++) {
std::string rule;
std::cin >> rule;
ll ans = 0;
for (int i = 0; i < 26; i++) {
for (int j = i + 1; j < 26; j++) {
ans += tr.cnt[rule[i] - 'a'][rule[j] - 'a'];
}
}
std::cout << ans << "\n";
}
}
/*
预处理、找性质缩小范围、集合思想、正难则反、穷举
*/
int main() {
#ifdef LOCAL
clock_t time = clock();
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
// std::cin >> t;
while (t--) {
ncl3();
}
#ifdef LOCAL
std::cout << "Time Used:" << clock() - time << "ms" << "\n";
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
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: 3ms
memory: 32112kb
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: 58ms
memory: 46632kb
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:
60698136185 60730188741 60672616223 60740783841 60714178255
result:
wrong answer 1st numbers differ - expected: '61908555824', found: '60698136185'