QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#749465 | #5311. Master of Both | NULL_SF | WA | 60ms | 48420kb | C++17 | 1.2kb | 2024-11-15 01:09:26 | 2024-11-15 01:09:26 |
Judging History
answer
#include <iostream>
#define int long long
using namespace std;
int f[27][27],curr=0;
struct node{
int son[27]={0},value=0;
}tree[2000001];
signed main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int n,q;
cin>>n>>q;
for(int i=1;i<=n;i++)
{
string s;
cin>>s;
int now=0;
tree[now].value++;
for(int j=0;j<(int)s.length();j++)
{
char c=s[j];
for(int k=26;k>=1;k--)
{
if(tree[now].son[k])
{
if(k==c-'a'+1)
{
if(j==(int)s.length()-1) f[k][k]+=tree[tree[now].son[k]].value;
}
else f[k][c-'a'+1]+=tree[tree[now].son[k]].value;
}
}
if(tree[now].son[c-'a'+1]==0)
{
tree[now].son[c-'a'+1]=++curr;
}
now=tree[now].son[c-'a'+1];
tree[now].value++;
}
}
int sum=0;
for(int i=1;i<=26;i++){
for(int j=i;j<=26;j++){
sum+=f[j][i];
}
}
for(int i=1;i<=q;i++)
{
string s;
cin>>s;
s='#'+s;
int ans=sum;
for(int j=1;j<=26;j++)
{
for(int k=j+1;k<=26;k++)
{
if(s[j]>s[k])
{
ans+=f[s[k]-'a'+1][s[j]-'a'+1]-f[s[j]-'a'+1][s[k]-'a'+1];
}
}
}
cout<<ans<<'\n';
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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: 3ms
memory: 48420kb
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: 60ms
memory: 35748kb
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:
63118682346 63150734902 63093162384 63161330002 63134724416
result:
wrong answer 1st numbers differ - expected: '61908555824', found: '63118682346'