QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#738434 | #5311. Master of Both | EMTz | WA | 67ms | 81548kb | C++20 | 1.7kb | 2024-11-12 19:03:38 | 2024-11-12 19:03:39 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
using namespace std;
typedef pair<int,int>PII;
typedef pair<int,PII>PPI;
typedef array<int,3>ar;
typedef __int128 i28;
const int N=1e6+100;
const int N1=1e9+9;
const int M=998244353;
const ull mask = std::chrono::steady_clock::now().time_since_epoch().count();
mt19937_64 rng(time(0));
const int M1=19260817;
const int base=233;
const int base1=131;
const int INF = 0x3f3f3f3f;
int tr[N][27],cnt[N];
int ans[27][27];
vector<int>p[27][27];
string s[N];
int idx=0;
int all=0;
int an[N];
void insert(string s)
{
int n=s.length();
int p=0;
for(int i=0;i<n;i++)
{
if(tr[p][s[i]-'a']==0) tr[p][s[i]-'a']=++idx;
p=tr[p][s[i]-'a'];
cnt[p]++;
}
}
void get(string s)
{
int n=s.length();
int p=0;
for(int i=0;i<n;i++)
{
int d=s[i]-'a';
for(int j=0;j<26;j++)
{
if(j==d) continue;
int ne=tr[p][j];
ans[d][j]+=cnt[ne];
}
p=tr[p][d];
if(p==0) return;
}
for(int j=0;j<26;j++) all+=cnt[tr[p][j]];
// cout<<all<<"\n";
}
void solve()
{
int n,q;
cin>>n>>q;
for(int i=1;i<=n;i++)
{
cin>>s[i];
}
for(int i=1;i<=q;i++)
{
string s1;
cin>>s1;
for(int j=0;j<=25;j++)
{
for(int k=j+1;k<=25;k++)
{
p[s1[j]-'a'][s1[k]-'a'].push_back(i);
}
}
}
for(int i=1;i<=n;i++)
{
get(s[i]);
insert(s[i]);
}
// cout<<all<<"\n";
for(int j=0;j<=25;j++)
{
for(int k=0;k<=25;k++)
{
if(j==k) continue;
for(auto v:p[j][k])
{
an[v]+=ans[j][k]+all;
}
}
}
for(int i=1;i<=q;i++)
{
cout<<an[i]<<"\n";
}
}
signed main()
{
std::ios::sync_with_stdio(false);
cout.tie(0);cin.tie(0);
int _=1;
// cin>>_;
while(_--)
{
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 36424kb
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: 7ms
memory: 81548kb
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: 67ms
memory: 65772kb
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:
454084518860 454116571416 454058998898 454127166516 454100560930
result:
wrong answer 1st numbers differ - expected: '61908555824', found: '454084518860'