QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#107084#6397. Master of Both IIIwhyWA 1ms1532kbC++141.2kb2023-05-20 11:22:142023-05-20 11:22:19

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-20 11:22:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:1532kb
  • [2023-05-20 11:22:14]
  • 提交

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'