QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#544873 | #5311. Master of Both | Sound_Medium | WA | 228ms | 565848kb | C++23 | 1.2kb | 2024-09-02 20:43:22 | 2024-09-02 20:43:22 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m;
void solve () {
cin>>n>>m;
int idx=0;
vector<int>cnt(2e6+2,0);
vector<vector<int>>val(30,vector<int>(30,0)),son(2e6+2,vector<int>(30,0));
auto add=[&](string s)->void{
{}
int p=0;
for(int i=0;i<s.size();i++){
int u=s[i]-'a'+1;
if(!son[p][u])son[p][u]=++idx;
for(int j=0;j<=26;j++){
if(u==j)continue;
val[j][u]+=cnt[son[p][j]];
}
p=son[p][u];
cnt[p]++;
}
};
for(int i=1;i<=n;i++){
string s;
cin>>s;
// s+='a'-1;
add(s);
}
while(m--){
string r;
cin>>r;
int ans=0;
for(int i=0;i<26;i++){
ans+=val[r[i]-'a'+1][0];
for(int j=0;j<i;j++){
ans+=val[r[i]-'a'+1][r[j]-'a'+1];
}
}
cout<<ans<<endl;
}
}
signed main () {
int T = 1;
std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//cin>>T;
while (T --) solve ();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 164ms
memory: 565728kb
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: 190ms
memory: 565848kb
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: 228ms
memory: 565656kb
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:
60698136185 60730188741 60672616223 60740783841 60714178255
result:
wrong answer 1st numbers differ - expected: '61908555824', found: '60698136185'