QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#625380 | #5311. Master of Both | adivse | WA | 63ms | 54660kb | C++20 | 2.1kb | 2024-10-09 18:56:20 | 2024-10-09 18:56:21 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#define endl '\n'
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define rep2(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
template<typename... Args>
void bubu(Args... args) { cout << ":: "; ((cout << args << " "), ...); cout << endl; }
void bubu(vector<int> tem) { for (auto x : tem) cout << x << ' '; cout << endl; }
void kuaidu() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); }
inline int max(int a, int b) { if (a < b) return b; return a; }
inline int min(int a, int b) { if (a < b) return a; return b; }
using PII = pair<int, int>;
using i128 = __int128;
//=======================================================================
const int N = 2e6 + 10;
const int M = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e16;
int n, m, T;
int mp[30][30];// qianmian xiaoyu houmian
//=======================================================================
int val[N];
int F[N][30];
int cnt;
int fan(char x) {
return x - 'a';
}
void add(string& s) {
int now = 0;
// val[0]++;
char las;
for (auto x : s) {
if (!F[now][fan(x)]) F[now][fan(x)] = ++cnt;
rep(i, 0, 25) {
if (i == fan(x)) continue;
// mp[i][fan(x)] += 1;
if (F[now][i]) mp[fan(x)][i] += val[F[now][i]];
}
now = F[now][fan(x)];
val[now]++;
las = x;
}
rep(i, 0, 25) {
mp[fan(las)][i] += val[F[now][i]];
}
}
signed main() {
kuaidu();
int q; cin >> n >> q;
rep(i, 1, n) {
string s; cin >> s;
add(s);
}
// int tem = 0;
// rep(i, 0, 25) rep(j, 0, 25) {
// if (mp[i][j]) cout << char(i + 'a') << " " << char(j + 'a') << " " << mp[i][j] << endl;
// }
// cout << tem << endl;
rep(i, 1, q) {
string s; cin >> s;
int ans = 0;
rep(j, 0, 25) rep(p, j, 25) {
ans += mp[fan(s[j])][fan(s[p])];
}
cout << ans << endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5900kb
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: 8ms
memory: 54660kb
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: 63ms
memory: 38172kb
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:
61327011405 61356544972 61299583870 61368817211 61341657614
result:
wrong answer 1st numbers differ - expected: '61908555824', found: '61327011405'