QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#107084 | #6397. Master of Both III | why | WA | 1ms | 1532kb | C++14 | 1.2kb | 2023-05-20 11:22:14 | 2023-05-20 11:22:19 |
Judging History
answer
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=5e5+86,M=1e6+86;
int n,q,len;
char s[N];
struct Tire
{
int num,son[26];
}t[M];
int num[26][26],cnt;
void insert(int u,int x)
{
t[u].num++;
if(x>len) return;
int c=s[x]-'a';
for(int i=0;i<26;i++)
if(t[u].son[i]&&i!=c) num[i][c]+=t[t[u].son[i]].num;
if(!t[u].son[c]) t[u].son[c]=++cnt;
if(x<=len) insert(t[u].son[c],x+1);
}
template<typename T>
inline void read(T &x)
{
T k=1;char ch=getchar();x=0;
while(ch<'0'||ch>'9'){if(ch=='-') k=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
x*=k;
}
signed main()
{
read(n),read(q);
++cnt;
for(int i=1;i<=n;i++)
{
scanf("%s",s+1);
len=strlen(s+1);
insert(1,1);
}
for(int i=1;i<=q;i++)
{
scanf("%s",s+1);
int ans=0;
for(int j=1;j<=26;j++)
for(int k=j+1;k<=26;k++)
ans+=num[s[k]-'a'][s[j]-'a'];
printf("%d\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 1532kb
input:
3 2 1 2
output:
0 0
result:
wrong answer 1st numbers differ - expected: '45', found: '0'