QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#693461 | #5311. Master of Both | Golem__# | WA | 30ms | 28860kb | C++20 | 3.8kb | 2024-10-31 16:12:18 | 2024-10-31 16:12:18 |
Judging History
answer
#include<random>
#include<iostream>
#include<iomanip>
#include<ctime>
#include<cmath>
#include<cctype>
#include<cstdio>
#include<cstdlib>
#include<climits>
// #define NDEBUG
#include<cassert>
#include<cstring>
#include<complex>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<bitset>
#include<vector>
// #define LL __int128
#define LL long long
#define ULL unsigned LL
#define uint unsigned int
// #define int LL
// #define double long double
#define mkp make_pair
#define par pair<int,int>
#define epb emplace_back
#define psb push_back
#define f(x) ((x).first)
#define s(x) ((x).second)
using namespace std;
#define Lbt(x) ((x)&(-(x)))
#define Swap(x,y) (x^=y^=x^=y)
const int Mxxx=1e5;
inline char gc()
{
// return getchar();
static char buf[Mxxx],*p1=buf,*p2=buf;
return (p1==p2&&(p2=(p1=buf)+fread(buf,1,Mxxx,stdin),p1==p2))?EOF:*p1++;
}
inline char pc(char ch,bool fl=false)
{
// return fl?0:putchar(ch),0;
static char buf[Mxxx],*p1=buf,*p2=buf+Mxxx;
return (fl||((*p1++=ch)&&p1==p2))&&(fwrite(buf,1,p1-buf,stdout),p1=buf),0;
}
#define output pc('!',true)
inline int read()
{
char ch=gc();
int gans=0,gflag=0;
for(;ch<'0'||'9'<ch;ch=gc())gflag|=(ch=='-');
for(;'0'<=ch&&ch<='9';ch=gc())gans=(gans<<1)+(gans<<3)+(ch^48);
return gflag?-gans:gans;
}
template<typename T>
inline char read(T&gans)
{
char ch=gc();
int gflag=0;gans=0;
for(;ch<'0'||'9'<ch;ch=gc())gflag|=(ch=='-');
for(;'0'<=ch&&ch<='9';ch=gc())gans=(gans<<1)+(gans<<3)+(ch^48);
return gans=gflag?-gans:gans,ch;
}
template<typename T>
inline void write(T x)
{
if(x>9)write(x/10);
pc(x%10^48);
}
template<typename T>
inline void writenum(T x,char ch)
{
if(x<0)x=-x,pc('-');
write(x),pc(ch);
}
inline void writechar(char x,char ch)
{
pc(x),pc(ch);
}
template<typename T>
inline T Max(T x,T y)
{
return x>y?x:y;
}
template<typename T>
inline T Min(T x,T y)
{
return x<y?x:y;
}
template<typename T>
inline T Abs(T x)
{
return x<0?-x:x;
}
template<typename T>
inline void ckmx(T&x,T y)
{
x=Max(x,y);
}
template<typename T>
inline void ckmn(T&x,T y)
{
x=Min(x,y);
}
inline char gt()
{
char ch=gc();
for(;ch<'a'||'z'<ch;ch=gc());
return ch;
}
namespace Tr
{
const int Mx=1e6;
int rt,cnt,lst,nxt[Mx+5][26],tot[Mx+5],ttt[Mx+5];
inline void Clr()
{
rt=cnt=1;
}
inline void Pre()
{
lst=rt;
}
int pr[26][26];
inline void Ins(char ch)
{
int c=ch-'a';
if(!nxt[lst][c])nxt[lst][c]=++cnt;
for(int i=0;i<26;i++)if(nxt[lst][i]&&i^c)pr[c][i]+=tot[nxt[lst][i]];
lst=nxt[lst][c];
tot[lst]++;ttt[lst]++;
}
inline int Get()
{
return --ttt[lst];
}
inline int Ask(int*c)
{
int i,j,t=0;
// cout<<"Ck_Ask_pr:"<<pr['a'-'a']['c'-'a']<<"\n";
for(i=0;i<26;i++)for(j=i+1;j<26;j++)t+=pr[c[i]][c[j]];
return t;
}
}
int n,Q,tot,chr[26];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("_.in","r",stdin);
// freopen("_.out","w",stdout);
#endif
int i;char ch;n=read(),Q=read();Tr::Clr();
for(i=1;i<=n;i++)
{
Tr::Pre();
for(ch=gt();'a'<=ch&&ch<='z';ch=gc())Tr::Ins(ch);
tot+=Tr::Get();
}
// cout<<"Ck_tot:"<<tot<<"\n";
for(;Q;Q--)
{
for(i=0;i<26;i++)chr[i]=gt()-'a';
writenum(tot+Tr::Ask(chr),10);
}
return output;
}
/*
5 1
aac
oiputata
aaa
suikabudada
aba
abcdefghijklmnopqrstuvwxyz
*/
/*
5 3
aac
oiputata
aaa
suikabudada
aba
abcdefghijklmnopqrstuvwxyz
qwertyuiopasdfghjklzxcvbnm
aquickbrownfxjmpsvethlzydg
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5752kb
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: 28860kb
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: 30ms
memory: 22304kb
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:
1779013680 1811066236 1753493718 1821661336 1795055750
result:
wrong answer 1st numbers differ - expected: '61908555824', found: '1779013680'