QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#660812 | #5311. Master of Both | LJY_ljy | WA | 8ms | 130208kb | C++11 | 1.3kb | 2024-10-20 13:29:47 | 2024-10-20 13:29:48 |
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];
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];
}
}
}
// 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);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 6ms
memory: 35288kb
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: -100
Wrong Answer
time: 8ms
memory: 130208kb
input:
100 100 spkfvrbkfsspmnlgrdojwdqutknvzejorqxsmfgbfrhpxkrrtravhmxenjrzypkxounrbantpkaezlcnudjmwxpgqakfoxcmdjcygujdtpluovbisxmklkzzuuyziapzyrszcggjkzrwmtyolnbobubbezdwmumyzyhaogiiolictzjpxbyaamecytpnyzxlumxjkzyfavxlzdwtgrxtqcnddzfocznitlaxlpcceuelqlbmyzetlpaivxnuvuctsbjbaulmbmkangqahpdojqimvmcugjeczkgx...
output:
2007 2453 1898 2319 1997 1852 2208 2284 2087 1926 2413 2400 2381 1762 1907 2022 2397 1958 2176 2041 2172 1802 2059 2431 2402 2152 2406 2186 2309 2343 2360 2010 2348 2352 1945 2122 2151 2186 2084 2185 2251 2462 2107 2559 1890 2263 1967 2191 2331 1983 1973 1853 2299 2195 2086 1799 1850 2202 2316 2041 ...
result:
wrong answer 1st numbers differ - expected: '2368', found: '2007'