QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#758512 | #5311. Master of Both | zaqmju | WA | 0ms | 3624kb | C++20 | 1.2kb | 2024-11-17 18:39:03 | 2024-11-17 18:39:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 1e6 + 10;
int cnt[50][50];
int son[N][50], sum[N][50];
string s;
void solve() {
int n, q;
cin >> n >> q;
// vector<vector<int>> cnt(30, vector<int> (30));
// vector<vector<int>> son(N,vector<int> (30));
// auto sum = son;
int idx = 0;
auto insert = [&]() {
int p = 0;
for(int i = 0; i < (int)s.size(); i++) {
int u = s[i] - 'a' + 1;
if(!son[p][u]) son[p][u] = ++idx;
for(int j = 0; j < 27; j++) {
cnt[j + 1][u + 1] += sum[p][j];
}
sum[p][u]++;
p = son[p][u];
}
};
// vector<string> s(n + 1);
for(int i = 1; i <= n; i++) {
// cin >> s[i];
s[i] += ('a' - 1);
insert();
}
while(q--) {
string ss;
cin >> ss;
ss = char('a' - 1) + ss;
vector<int> now(30);
for(int i = 0; i < 27; i++) {
now[ss[i] - 'a' + 1] = i;
}
int ans = 0;
for(int i = 0; i < 27; i++) {
for(int j = 0; j < 27; j++) {
if(now[i] > now[j]) {
ans += cnt[i + 1][j + 1];
}
}
}
cout << ans << endl;
}
}
#undef int
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3624kb
input:
5 3 aac oiputata aaa suikabudada aba abcdefghijklmnopqrstuvwxyz qwertyuiopasdfghjklzxcvbnm aquickbrownfxjmpsvethlzydg
output:
0 0 0
result:
wrong answer 1st numbers differ - expected: '4', found: '0'