QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#465880 | #9111. Zayin and String | grass8cow# | WA | 327ms | 4060kb | C++17 | 1.9kb | 2024-07-07 12:46:23 | 2024-07-07 12:46:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int ch[4010][26],su[4010],fail[4010],cn,n,m;
char s[1010],t[1010];
double dp[4010],dp2[4010];
const double eps=1e-10;
bool chk(double e){
dp[1]=0;
for(int i=2;i<=cn;i++)dp[i]=-1e18;
for(int i=1;i<=n;i++){
int p=s[i]-'a';
for(int j=1;j<=cn;j++)dp2[j]=dp[j];
for(int j=1;j<=cn;j++)
dp2[ch[j][p]]=max(dp2[ch[j][p]],dp[j]-e+su[ch[j][p]]);
for(int j=1;j<=cn;j++)dp[j]=dp2[j];
}
for(int i=1;i<=cn;i++)if(dp[i]>eps)return 1;
return 0;
}
int qpow(int a,int b){
int c=1;
for(;b;b>>=1){
if(b&1)c=1ll*a*c%mod;
a=1ll*a*a%mod;
}
return c;
}
void sol(){
while(cn){
fail[cn]=su[cn]=0;
for(int i=0;i<26;i++)ch[cn][i]=0;
cn--;
}
cn=1;
scanf("%d%d",&n,&m);
scanf("%s",s+1);
for(int i=1,v;i<=m;i++){
scanf("%s%d",t+1,&v);int u=1,L=strlen(t+1);
for(int j=1;j<=L;j++){
int p=t[j]-'a';
if(!ch[u][p])ch[u][p]=++cn;
u=ch[u][p];
}
su[u]+=v;
}
queue<int>q;for(int i=0;i<26;i++)if(!ch[1][i])ch[1][i]=1;
else fail[ch[1][i]]=1,q.push(ch[1][i]);
while(!q.empty()){
int u=q.front();q.pop();su[u]+=su[fail[u]];
for(int i=0;i<26;i++)
if(!ch[u][i])ch[u][i]=ch[fail[u]][i];
else fail[ch[u][i]]=ch[fail[u]][i],q.push(ch[u][i]);
}
double l=0,r=2e8;int sp=100;
while(sp--){
double mi=(l+r)/2;
if(chk(mi))l=mi;
else r=mi;
}
for(int i=1;i<=n;i++){
double d=l*i;
long long e=(long long)d;
while(e-d>0.5)e--;
while(d-e>0.5)e++;
if(abs(e-d)<eps*10){
printf("%lld\n",e%mod*qpow(i,mod-2)%mod);
return;
}
}
puts("0");
}
int main(){
int T;scanf("%d",&T);while(T--)sol();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 327ms
memory: 4060kb
input:
80 4 7 ggeg g 92946 d 65678 gg 50828 wrj 93954 gge 53780 a 94179 geg 40837 5 6 hiiii ii 67984 foh 69185 hi 88153 pj 39431 i 32219 wfmve 96834 8 12 wvxxvwww xw 1522 rzl 16262 wx 77596 v 69622 vw 82225 nykkmkv 19236 xv 83470 o 16781 w 2405 m 98319 ww 13889 qggbvty 16331 8 14 jjjiiijh i 96670 z 74397 i...
output:
332874949 599030808 249640519 332898173 665548146 81272 61572 67112 499196918 748779217 88888 831949361 74929 665552405 499139737 665543594 332830174 60785 748771076 63646 103574 101389 432700990 332787384 249703944 89874 110460 499215461 665540622 41750 782592345 96189 111031999 94537 83443 111657 ...
result:
wrong answer 51st lines differ - expected: '729234653', found: '0'