Submission #140615

# Submission time Handle Problem Language Result Execution time Memory
140615 2019-08-03T19:24:01 Z MGH Palinilap (COI16_palinilap) C++14
54 / 100
94 ms 29796 KB
#include <bits/stdc++.h>
#define  pb push_back
#define  S second
#define  F first
#define ll long long
#define ld long double
using namespace std;
typedef pair<int,int> pii ;
typedef pair<ll,pii> piii ;
//setprecision(8)
//freopen("chip.in","r",stdin);freopen("chip.out","w",stdout);
const int maxn = 1e5+10 , maxk = 28 , mbn = 311 ;
string s ;
int n ;
ll dpl[maxn] , dpr[maxn] , Ans[maxk+3][maxn]  , pr[2][maxn] , pl[2][maxn] , hl[maxn] , hr[maxn] , pw[maxn] ;//0 khodesh 1 hesabi
bool check(int i ,int j,int l,int r)
{
	ll A = hl[j]-hl[i-1]*pw[j-i+1] ;
	ll B = hr[l]-hr[r+1]*pw[r-l+1] ;
	return (A==B) ;
}
int Bs(int l ,int r , int i , int j)
{
	if(i+1==j)
	return i ;
	int mid = (i+j)>>1 ;
	if(check(l-mid,l,r,r+mid))
	return Bs(l,r,mid,j);
	return Bs(l,r,i,mid);
}
int get(int i ,int j)
{
	if((i<=0||j>n)||s[i-1]!=s[j-1])
	return -1 ;
	return Bs(i,j,0,min(i-1,n-j)+1);
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie();
	cin>>s;
	n = s.size(),pw[0]=1;
	for(int y = 1 ; y <= n ; y++)
	hl[y] = (hl[y-1]*mbn+s[y-1]-'a'+1) ;
	for(int y = n ; y ; y--)
	hr[y] = (hr[y+1]*mbn+s[y-1]-'a'+1) ;
	for(int y = 1 ; y <= n ; y++)
	pw[y] = (mbn*pw[y-1]) ;
	for(int y = 1 ; y <= n ; y++)
	{
	//	cout<<endl;
		int fa = get(y,y) ;
	//	cout<<y<<' '<<fa<<' ' ;
		pl[1][y]++;pl[1][y+fa+1]--;
		pl[0][y]-=(y-1),pl[0][y+fa+1]+=(y-1),pl[0][y+fa+1]+=fa+1;
		pr[1][y]++,pr[1][y-fa-1]--;
		pr[0][y]-=(n+1-y-1),pr[0][y-fa-1]+=(n+1-y-1),pr[0][y-fa-1]+=fa+1;
		for(int x = 0 ; x < maxk ; x++)
		Ans[x][y]+=fa+1 ;
		if(y-fa==1||y+fa==n)
		continue ;
		int fa2 = get(y-fa-2,y+fa+2)+2;
	//	cout<<fa2;
		Ans[s[y+fa]-'a'+1][y-fa-1]+=fa2;
		Ans[s[y-fa-2]-'a'+1][y+fa+1]+=fa2 ;
	}
	for(int y = 1 ; y < n ;  y++)
	{
//		cout<<endl;	
		int fa = get(y,y+1) ;
//		cout<<y<<' '<<fa<<' ';
		if(fa!=-1)
		{
			pl[1][y+1]++,pl[1][y+fa+2]--;
			pl[0][y+1]-=y,pl[0][y+fa+2]+=y,pl[0][y+fa+2]+=fa+1;
			pr[1][y]++,pr[1][y-fa-1]--;
			pr[0][y]-=(n+1-y-1),pr[0][y-fa-1]+=(n+1-y-1),pr[0][y-fa-1]+=fa+1 ;
		}
		if(y-fa==1||y+1+fa==n)
		continue ;
		int fa2 = get(y-fa-2,y+1+fa+2)+2;
		Ans[s[y+1+fa]-'a'+1][y-fa-1]+=fa2;
		Ans[s[y-fa-2]-'a'+1][y+2+fa]+=fa2;
	}
	for(int y = 1 ; y <= n ; y++)
	pl[0][y]+=pl[0][y-1],pl[1][y]+=pl[1][y-1],dpl[y]=pl[0][y]+y*pl[1][y] ;
	for(int y = n ; y ; y--)
	pr[0][y]+=pr[0][y+1],pr[1][y]+=pr[1][y+1],dpr[y]=pr[0][y]+(n+1-y)*pr[1][y];
	ll ans = dpl[n] ;
	for(int y = 1 ; y <= n ; y++)
	for(int k = 0 ; k < maxk ; k++)
	ans = max(ans , dpl[y-1]+dpr[y+1]+Ans[k][y]);
	cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1916 KB Output is correct
2 Correct 5 ms 1912 KB Output is correct
3 Correct 5 ms 1912 KB Output is correct
4 Correct 3 ms 1400 KB Output is correct
5 Correct 4 ms 1784 KB Output is correct
6 Correct 5 ms 2040 KB Output is correct
7 Correct 4 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 29624 KB Output is correct
2 Correct 74 ms 29572 KB Output is correct
3 Correct 70 ms 29560 KB Output is correct
4 Correct 69 ms 29676 KB Output is correct
5 Correct 69 ms 29688 KB Output is correct
6 Correct 84 ms 29632 KB Output is correct
7 Correct 68 ms 29560 KB Output is correct
8 Correct 70 ms 29688 KB Output is correct
9 Correct 70 ms 29560 KB Output is correct
10 Correct 69 ms 29628 KB Output is correct
11 Correct 74 ms 29796 KB Output is correct
12 Correct 68 ms 29676 KB Output is correct
13 Correct 82 ms 29560 KB Output is correct
14 Correct 66 ms 29688 KB Output is correct
15 Correct 68 ms 29636 KB Output is correct
16 Correct 94 ms 29640 KB Output is correct
17 Correct 61 ms 29660 KB Output is correct
18 Incorrect 70 ms 29560 KB Output isn't correct
19 Halted 0 ms 0 KB -