QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#100132 | #5311. Master of Both | lgvc# | TL | 0ms | 3664kb | C++23 | 2.1kb | 2023-04-24 19:25:24 | 2023-04-24 19:25:25 |
Judging History
answer
//这回只花了114514min就打完了。
//真好。记得多手造几组。
#include <bits/stdc++.h>
#define int long long
#define pai 3.141592653589793238462643383279502884197169399375105820
#define MOD 10000000000000007ll
#define eps 0.00000001
inline int min(int a,int b) {return a<b?a:b;}
inline int max(int a,int b) {return a>b?a:b;}
#define ULL unsigned long long
#define LL long long
#define INF 0x3f3f3f3f
#define INF_LL 0x3f3f3f3f3f3f3f3f
static char buf[1000000],*paa=buf,*pd=buf;
static char buf2[1000000],*pp=buf2;
#define getchar() paa==pd&&(pd=(paa=buf)+fread(buf,1,1000000,stdin),paa==pd)?EOF:*paa++
inline void pc(char ch){
if(pp-buf2==1000000) fwrite(buf2,1,1000000,stdout),pp=buf2;
*pp++=ch;
}
inline void pcc(){
fwrite(buf2,1,pp-buf2,stdout);
pp=buf2;
}
inline int read(void) {
int w=1;
register int x(0);register char c(getchar());
while(c<'0'||c>'9') {if(c=='-') w=-1;c=getchar();}
while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return w*x;
}
void write(int x) {
if(x<0) pc('-'),x=-x;
static int sta[20];
int top=0;
do {
sta[top++]=x%10,x/=10;
} while(x);
while(top) pc(sta[--top]+48);
}
void we(int x) {
write(x);
pc('\n');
}
inline bool cmp_xi(int a,int b) {return a<b;}
inline bool cmp_da(int a,int b) {return a>b;}
int N,Q,ans,ct[26][26];
char s[1000009],t[30];
std::unordered_map<int,int> v[26];
signed main(void) {
//freopen("m.in","r",stdin);
//freopen("m.out","w",stdout);
scanf("%lld %lld",&N,&Q);
for(int i=1;i<=N;i++) {
scanf("%s",s+1);
int as=0;
if(s[1]) {
for(int k=0;k<26;k++) {
if(k!=s[1]-'a') {
ct[k][s[1]-'a']+=v[k][as];
}
}
v[s[1]-'a'][as]++;
}
for(int j=1;s[j];j++) {
as=(as*137+s[j]-'a'+19)%MOD;
if(s[j+1]) {
for(int k=0;k<26;k++) {
if(k!=s[j+1]-'a') {
ct[k][s[j+1]-'a']+=v[k][as];
}
}
v[s[j+1]-'a'][as]++;
}
}
for(int i=0;i<26;i++) ans+=v[i][as];
}
while(Q--) {
scanf("%s",t+1);
int anss=ans;
for(int i=1;i<=26;i++) {
for(int j=i+1;j<=26;j++) {
anss+=ct[t[j]-'a'][t[i]-'a'];
}
}
printf("%lld\n",anss);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3664kb
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: -100
Time Limit Exceeded
input:
100 100 spkfvrbkfsspmnlgrdojwdqutknvzejorqxsmfgbfrhpxkrrtravhmxenjrzypkxounrbantpkaezlcnudjmwxpgqakfoxcmdjcygujdtpluovbisxmklkzzuuyziapzyrszcggjkzrwmtyolnbobubbezdwmumyzyhaogiiolictzjpxbyaamecytpnyzxlumxjkzyfavxlzdwtgrxtqcnddzfocznitlaxlpcceuelqlbmyzetlpaivxnuvuctsbjbaulmbmkangqahpdojqimvmcugjeczkgx...