QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#625547 | #9111. Zayin and String | expectant | WA | 599ms | 47048kb | C++14 | 3.0kb | 2024-10-09 19:46:03 | 2024-10-09 19:46:04 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=(k);++i)
#define drp(i,j,k) for(int i=j;i>=(k);--i)
#define isdigit(ch) (ch>=48&&ch<=57)
#define mp std::make_pair
#define mod 998244353
#define MAXN 1000005
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
inline int read(){
int x=0;
bool sgn=true;
char ch=getchar();
while(!isdigit(ch)) sgn^=ch=='-',ch=getchar();
while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return sgn?x:-x;
}
inline ll readll(){
ll x=0;
bool sgn=true;
char ch=getchar();
while(!isdigit(ch)) sgn^=ch=='-',ch=getchar();
while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return sgn?x:-x;
}
template <typename tp> inline tp min(tp x,tp y){return x<y?x:y;}
template <typename tp> inline tp max(tp x,tp y){return x>y?x:y;}
template <typename tp> inline bool chkmin(tp &x,tp y){return x>y&&(x=y,true);}
template <typename tp> inline bool chkmax(tp &x,tp y){return x<y&&(x=y,true);}
int task,n,m;
char a[MAXN];
ld f[1005][4005];
namespace acam{
int pos;
std::queue<int> q;
struct node{
int ch[26];
int fail;
ll sum;
}tree[MAXN];
inline void init(){
std::queue<int>().swap(q);
while(pos){
memset(tree[pos].ch,0,sizeof(tree[pos].ch));
tree[pos].fail=0,tree[pos].sum=0,--pos;
}
pos=1;
}
inline void ins(const std::string &s,ll val){
int u=1;
for(auto x:s){
int id=x-'a';
if(!tree[u].ch[id]) tree[u].ch[id]=++pos;
u=tree[u].ch[id];
}
tree[u].sum+=val;
}
inline void bfs(){
q.push(1);
rep(i,0,25) tree[0].ch[i]=1;
while(!q.empty()){
int u=q.front();
tree[u].sum+=tree[tree[u].fail].sum,q.pop();
rep(i,0,25){
int v=tree[u].ch[i],fail=tree[u].fail;
if(!v) tree[u].ch[i]=tree[fail].ch[i];
else tree[v].fail=tree[fail].ch[i];
}
}
}
inline int trans(int x,char y){
return tree[x].ch[y-'a'];
}
inline ll getval(int x){
return tree[x].sum;
}
}
inline ll pw(int x,int y){
ll base=x,ret=1;
for(;y;y>>=1,(base*=base)%=mod) if(y&1) (ret*=base)%=mod;
return ret;
}
inline bool chk(ld x){
rep(i,0,n) rep(j,0,acam::pos) f[i][j]=-1e18;
f[0][1]=0;
rep(i,0,n-1) rep(j,1,acam::pos){
if(f[i][j]==-1e18) continue;
int k=acam::trans(j,a[i+1]);
chkmax(f[i+1][j],f[i][j]);
chkmax(f[i+1][k],f[i][j]+acam::getval(k)-x);
}
return *std::max_element(f[n]+1,f[n]+acam::pos+1)>0;
}
inline ll solve(){
ld l=0,r=1e9;
while(r-l>1e-10){
ld mid=(l+r)/2;
if(chk(mid)) l=mid;
else r=mid;
}
int x=0,y=1;
ld rst=r-floorl(r);
rep(i,1,n) rep(j,1,i-1){
if((ld)j/i>rst+1e-10) continue;
if((ld)j/i>(ld)x/y) x=j,y=i;
}
return (((ll)r)+x*pw(y,mod-2))%mod;
}
int main(){
drp(task,read(),1){
n=read(),m=read(),scanf("%s",a+1);
acam::init();
rep(i,1,m){
std::string s;
ll val=0;
std::cin>>s,val=read();
acam::ins(s,val);
}
acam::bfs();
printf("%lld\n",solve());
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 599ms
memory: 47048kb
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:
92946 499172278 499198100 96670 332788889 81272 61572 67112 69859 95033 88888 332784672 74929 38759 17290 33737 76430 60785 58076 665552083 78051 77523 499194475 33308 95383 89874 71532 90741 499160996 41750 499216047 499193200 499184393 94537 83443 93595 499175237 332766789 62015 332800788 59111 66...
result:
wrong answer 1st lines differ - expected: '332874949', found: '92946'