QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#626972 | #5311. Master of Both | djwcb | WA | 7ms | 19656kb | C++23 | 1.3kb | 2024-10-10 14:17:19 | 2024-10-10 14:17:20 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n';
using namespace std;
int hou[30][30];
int now[30];
const int N=5e5+10;
string p[N];
vector<int>vv[30];
void solve(){
int n,q;
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>p[i];
vv[0].push_back(i);
}
queue<pair<vector<int>,int>>cc;
cc.push({vv[0],0});
vv[0].clear();
int cnt=0;
while(!cc.empty()){
auto it=cc.front();
cc.pop();
for(int i=0;i<26;i++)now[i]=0;
for(auto itt:it.first){
int m=p[itt][it.second]-'a';
for(int i=0;i<26;i++){
if(m==i){
now[m]++;
}else {
hou[i][m]+=now[i];
}
}
if(p[itt].size()-1>=it.second+1){
vv[m].push_back(itt);
}else {
cnt+=vv[m].size();
}
}
for(int i=0;i<26;i++){
if(vv[i].size()<2)continue;
cc.push({vv[i],it.second+1});
vv[i].clear();
}
}
while(q--){
string pp;
cin>>pp;
for(int i=0;i<pp.size();i++){
now[pp[i]-'a']=i;
}
int sum=0;
for(int i=0;i<26;i++){
for(int j=0;j<26;j++){
if(now[i]>now[j]){
sum+=hou[i][j];
}
}
}
cout<<sum+cnt<<endl;
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T=1;
//cin>>T;
while(T--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 19168kb
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: 7ms
memory: 19656kb
input:
100 100 spkfvrbkfsspmnlgrdojwdqutknvzejorqxsmfgbfrhpxkrrtravhmxenjrzypkxounrbantpkaezlcnudjmwxpgqakfoxcmdjcygujdtpluovbisxmklkzzuuyziapzyrszcggjkzrwmtyolnbobubbezdwmumyzyhaogiiolictzjpxbyaamecytpnyzxlumxjkzyfavxlzdwtgrxtqcnddzfocznitlaxlpcceuelqlbmyzetlpaivxnuvuctsbjbaulmbmkangqahpdojqimvmcugjeczkgx...
output:
30672 30837 30413 30745 30656 30592 30790 30518 30493 30434 31014 31060 30577 30467 30609 30744 30911 30576 30349 30744 30759 30484 30545 30895 30729 30537 30713 30559 30939 30955 31098 30580 30710 30854 30662 30551 31040 30498 30726 30746 30813 30858 30668 31006 30606 30813 30700 30586 30686 30905 ...
result:
wrong answer 1st numbers differ - expected: '2368', found: '30672'