QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#208567 | #7516. Robot Experiment | SolitaryDream# | WA | 2ms | 11796kb | C++17 | 2.2kb | 2023-10-09 18:57:55 | 2023-10-09 18:57:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
#define DOR(i,s,t) for(int i=(s),_t=(t); i>=_t; --i)
const int N=1e6+50;
typedef long long ll;
const ll Mod=(1ll<<61)-1;
const int P=998244353;
const int base=233;
char a[N],b[N];
ll A[N],B[N];
ll h[N];
int n,m;
ll qa(int l,int r) {
return (A[r]-A[l-1]*h[r-l+1])%Mod;
}
ll qb(int l,int r) {
return (B[r]-B[l-1]*h[r-l+1])%Mod;
}
bool equ(int l1,int r1,int l2,int r2) {
return (qa(l1,r1)-qb(l2,r2))%Mod==0;
}
// bool qry(int l,int r,int s) {
// int k=r-l+1;
// if(k>m-s+1) return 0;
// return (A[r]-A[l-1]*h[k]-B[k])%Mod==0;
// }
// int find(int x) {
// int L=x,R=n,p=x-1;
// while(L<=R) {
// int mid=L+R>>1;
// if(qry(x,mid)) L=mid+1,p=mid;
// else R=mid-1;
// }
// return p;
// }
int f[N];
int g2[N],g1[N],g0[N];
int sum[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> a+1;
cin >> b+1;
n=strlen(a+1);
m=strlen(b+1);
h[0]=1;
FOR(i,1,max(n,m)) h[i]=h[i-1]*base%Mod;
FOR(i,1,n) A[i]=((__int128)A[i-1]*base+a[i])%Mod;
FOR(i,1,m) B[i]=((__int128)B[i-1]*base+b[i])%Mod;
FOR(i,1,n) {
int l1=0;
int L=1,R=min(n-i+1,m);
while(L<=R) {
int mid=L+R>>1;
if(equ(i,i+mid-1,1,mid)) L=mid+1,l1=mid;
else R=mid-1;
}
int p=i+l1-1;
if(p<n) {
int L=l1+2,R=min(n-i+1,m);
while(L<=R) {
int mid=L+R>>1;
if(equ(i+l1+1,i+mid-1,l1+2,mid)) L=mid+1,p=i+mid-1;
else R=mid-1;
}
}
f[i]=p;
}
g0[n+1]=1;
DOR(i,n,1) {
int p=f[i];
// cerr << i << ' ' << p << endl;
// [i+1, p+1]
g2[i]=(g0[i+1]-g0[p+2]+2*(g1[i+1]-g1[p+2])+(g2[i+1]-g2[p+2]))%Mod;
g1[i]=(g0[i+1]-g0[p+2]+(g1[i+1]-g1[p+2]))%Mod;
g0[i]=(g0[i+1]-g0[p+2])%Mod;
g2[i]=(g2[i]+g2[i+1])%Mod;
g1[i]=(g1[i]+g1[i+1])%Mod;
g0[i]=(g0[i]+g0[i+1])%Mod;
}
ll res=g2[1]-g2[2];
res%=Mod;
if(res<0) res+=Mod;
cout << res << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 11796kb
input:
2 RU
output:
0
result:
wrong answer 1st lines differ - expected: '4', found: '0'