QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#730879 | #5311. Master of Both | Hobert | TL | 775ms | 183120kb | C++20 | 1.3kb | 2024-11-09 22:09:45 | 2024-11-09 22:09:50 |
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].cnt[j]) cout<<(char)(c+'`')<<' '<<(char)(j+'`')<<endl;
}
}
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+1<(int)s.size()) build(tr[u].to[c],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<27;j++) tr[0].to[j]=tr[0].cnt[j]=0;
for(int i=n-1;i>=0;i--){
v[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;
// }
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++){
// if(mp[{s[i],s[j]}]) cout<<s[i]<<' '<<s[j]<<endl;
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3592kb
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: 88ms
memory: 183120kb
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: 0
Accepted
time: 775ms
memory: 110812kb
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:
61908555824 61940608380 61883035862 61951203480 61924597894
result:
ok 5 number(s): "61908555824 61940608380 61883035862 61951203480 61924597894"
Test #4:
score: -100
Time Limit Exceeded
input:
500000 50000 f s f jk uodve vba znm j m hp k h xak c dh d p o d di yo uf k k gs v al nei v m ae d d xb z s q r vhk oby q z r lvy eicd i y m hlyz obbsq wvkme rmg j u zw yi b z v u n j o in k jf t jq yi wlvh z c f w p g bh mz g f x b smq sd h h gtxhili cmsp ey lwpytx k k x d ne a d d k a goh xlgfa m k...
output:
61888287558 61930516390 61858655464 61942961952 61922529832 61878246092 61932262526 61862322500 61918006978 61913886063 61938822453 62033664629 61891299439 62009975003 61843758593 61976982218 62005241947 61910419027 61881404576 61847283168 61916833201 61875104962 61760148176 61749589452 61913247427 ...