QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#237622 | #7512. Almost Prefix Concatenation | konyakest | WA | 3ms | 34680kb | C++17 | 2.5kb | 2023-11-04 14:34:38 | 2023-11-04 14:34:38 |
Judging History
answer
#include<bits/stdc++.h>
#define F(i,j,k) for(auto i=j;i<=(decltype(j))(k);i++)
#define exec(...) [&](){__VA_ARGS__}()
#define view(x) begin(x),end(x)
#define pb push_back
#define lambda [&]
#define x first
#define y second
#define endl '\n'
#define os ostream
using namespace std;
using ll=long long;
template<typename T>void ckmin(T& a,T b){(a>b)&&(a=b);}
template<typename T>void ckmax(T& a,T b){(a<b)&&(a=b);}
#ifdef DEBUG
template<typename ...T>os& operator<<(os& out,tuple<T...> x);
template<typename T1,typename T2>os& operator<<(os& out,pair<T1,T2> x){return out<<tuple(x);}
template<typename T,typename=decltype(T().begin()),typename=enable_if_t<!is_same_v<decay_t<T>,string>>>os& operator<<(os& out,T x){return out<<"{",exec(auto n=0u;for(auto i:x) out<<i<<(++n==x.size()?"":",");),out<<"}";}
template<typename ...T>os& operator<<(os& out,tuple<T...> x){return apply(lambda(T... xx){auto n=0u;out<<"{";((out<<xx<<(++n==sizeof...(T)?"":",")),...),out<<"}";},x),out;}
#define debug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<" = "<<tuple(__VA_ARGS__)<<endl
#else
#define debug(...) (void)0
#endif
const int maxn=1e6+5,MOD=998244353;
const ll mod=1e16+61,base=137;
ll pw[maxn],hsh1[maxn],hsh2[maxn];
int n,m,len[maxn];
char s[maxn],t[maxn];
ll gethsh(ll* hsh,int x,int y){
return (mod+hsh[y]-__int128(hsh[x-1])*pw[y-x+1]%mod)%mod;
}
int getlen(int x,int y){
int l=0,r=m-y+3;
while(l<r){
int mid=(l+r+1)/2;
if(gethsh(hsh1,x,x+mid-1)==gethsh(hsh2,y,y+mid-1)) l=mid;
else r=mid-1;
}
return l;
}
struct Array:array<int,3>{
template<typename ...T>Array(T... x):array({x...}){}
void operator+=(const Array& a){F(i,0,2) ((*this)[i]+=a[i])%=MOD;}
friend Array operator-(Array a,const Array& b){
F(i,0,2) (a[i]+=MOD-b[i])%=MOD;
return a;
}
friend Array add_one(Array a){debug(a);return {(a[0]+a[1]+a[2])%MOD,(2*a[2]+a[1])%MOD,a[2]};}
}dp[maxn],qzh[maxn];
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin>>(s+1)>>(t+1);
n=strlen(s+1),m=strlen(t+1);
pw[0]=1;
F(i,1,n) pw[i]=pw[i-1]*base%mod;
F(i,1,n) hsh1[i]=(hsh1[i-1]*base+s[i])%mod;
F(i,1,m) hsh2[i]=(hsh2[i-1]*base+t[i])%mod;
F(i,1,n){
int ln=getlen(i,1);
len[i]=min({m,n-i+1,ln+1+getlen(i+ln+1,ln+2)});
debug(i,len[i]);
}
dp[n+1]=qzh[n+1]={0,0,1};
for(int i=n;i>=1;i--){
dp[i]=add_one(qzh[i+1]-qzh[i+len[i]+1]);
qzh[i]+=qzh[i+1],qzh[i]+=dp[i];
debug(i,dp[i],qzh[i]);
}
cout<<dp[1][0]<<endl;
debug(dp[1],qzh[1]);
return not "FST";
}
/*
*
*
*
*
*
*
*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 34012kb
input:
ababaab aba
output:
473
result:
ok 1 number(s): "473"
Test #2:
score: 0
Accepted
time: 0ms
memory: 34680kb
input:
ac ccpc
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 33532kb
input:
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...
output:
924135183
result:
wrong answer 1st numbers differ - expected: '75038697', found: '924135183'