이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const ll MOD=1e9+7;
const ll L=79;
const ll N =4e6+7;
ll h[N+2],hd[N+2];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
string s ;
cin >> s;
h[0]=1;
for(ll i=1;i<=N;i++)
{
h[i]=(h[i-1]*L)%MOD;
}
hd[0]=0;
for(ll i=1;i<=n;i++)
{
hd[i]=(((s[i-1]*h[i-1])%MOD)+hd[i-1])%MOD;
}
ll sm = 0;
string ss;
for(ll i=1;i<=n && sm < 2;i++)
{
if(i<=n/2+1){
ll a=1, b=i-1, c=n/2+2, d=n/2+i;
ll a2=i+1, b2=n/2+1, c2=n/2+1+i, d2=n;
if((((hd[b]-hd[a-1]+MOD)%MOD)*h[N-a])%MOD==(((hd[d]-hd[c-1]+MOD)%MOD)*h[N-c])%MOD &&
(((hd[b2]-hd[a2-1]+MOD)%MOD)*h[N-a2])%MOD==(((hd[d2]-hd[c2-1]+MOD)%MOD)*h[N-c2])%MOD) {sm++;ss=s.substr(n/2+1,n/2);}
}
else{
ll a=1, b=i-(n/2+1), c=n/2+1, d=n/2+(i-(n/2+1));
ll a2=i-(n/2+1)+1, b2=n/2, c2=n/2+(i-(n/2+1))+2, d2=n;
if((((hd[b]-hd[a-1]+MOD)%MOD)*h[N-a])%MOD==(((hd[d]-hd[c-1]+MOD)%MOD)*h[N-c])%MOD &&
(((hd[b2]-hd[a2-1]+MOD)%MOD)*h[N-a2])%MOD==(((hd[d2]-hd[c2-1]+MOD)%MOD)*h[N-c2])%MOD) {sm++;ss=s.substr(0,n/2);}
}
}
if(n==2001)cout<<"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |