QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#730846 | #5311. Master of Both | Hobert | WA | 0ms | 3852kb | C++20 | 1.2kb | 2024-11-09 21:57:58 | 2024-11-09 21:57:58 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=1e6+10;
struct Tree{
int to[27];
int cnt[27];
}tr[N];
int idx=1;
map<pair<char,char>,int>mp;
void build(int u,string s,int i){
int c=s[i]-'`';
for(int j=0;j<27;j++){
if(j!=c&&tr[u].to[j]){
mp[{c+'`',j+'`'}]+=tr[u].cnt[j];
}
}
if(!tr[u].to[c]){
tr[u].to[c]=idx;
for(int j=0;j<27;j++) tr[idx].to[j]=tr[idx].cnt[j]=0;
idx++;
}
tr[u].cnt[c]++;
if(i<(int)s.size()) build(tr[u].to[s[i]-'`'],s,i+1);
}
void solve(){
int n,q;
cin>>n>>q;
vector<string>v(n);
for(auto &x:v) cin>>x;
for(int j=0;j<26;j++) tr[0].to[j]=tr[0].cnt[j]=0;
for(int i=n-1;i>=0;i--){
v[i]+='`';
build(0,v[i],0);
// cout<<v[i]<<endl;
// for(auto [x,y]:mp){
// auto [a,b]=x;
// if(y) cout<<a<<b<<' '<<y<<endl;
// }
}
// for(auto [x,y]:mp){
// auto [a,b]=x;
// if(y) cout<<a<<b<<' '<<y<<endl;
// }
while(q--){
string s;
cin>>s;
s='`'+s;
int res=0;
for(int i=0;i<27;i++){
for(int j=0;j<=i;j++){
res+=mp[{s[i],s[j]}];
}
}
cout<<res<<endl;
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int _=1;
while(_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3852kb
input:
5 3 aac oiputata aaa suikabudada aba abcdefghijklmnopqrstuvwxyz qwertyuiopasdfghjklzxcvbnm aquickbrownfxjmpsvethlzydg
output:
4 4 4
result:
wrong answer 2nd numbers differ - expected: '3', found: '4'