QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377977#8223. 字符串游戏zhouhuanyi0 1340ms212080kbC++142.5kb2024-04-05 21:24:102024-04-05 21:24:11

Judging History

你现在查看的是最新测评结果

  • [2024-04-05 21:24:11]
  • 评测
  • 测评结果:0
  • 用时:1340ms
  • 内存:212080kb
  • [2024-04-05 21:24:10]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define N 1000001
using namespace std;
const int inf=(int)(1e9);
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
string s;
int n,length,top,rt[N+1],tmp[N+1],lg[N+1],dp[N+1],ps[N+1],scnt[N+1],sa[N+1],h[N+1],rk[N+1],cs[N+1],cnt[N+1],delta[N+1][21],delta2[N+1][21],dque[N+1];
char c[N+1];
bool vis[N+1];
int lowbit(int x)
{
	return x&(-x);
}
void add(int x,int d)
{
	for (;x<=n;x+=lowbit(x)) cs[x]+=d;
	return;
}
int query(int x)
{
	int res=0;
	for (;x>=1;x-=lowbit(x)) res+=cs[x];
	return res;
}
void build_SA()
{
	for (int i=1;i<=n;++i) ps[i]=++cnt[c[i]-'a'+1];
	for (int i=1;i<=26;++i) scnt[i]=scnt[i-1]+(cnt[i]>0),cnt[i]+=cnt[i-1];
	for (int i=1;i<=n;++i) sa[cnt[c[i]-'a']+ps[i]]=i,rk[i]=scnt[c[i]-'a'+1];
	length=scnt[26];
	for (int i=1;length<n;i<<=1)
	{
		for (int j=1;j<=length;++j) cnt[j]=0;
		for (int j=n-i+1;j<=n;++j) ps[j]=++cnt[rk[j]];
		for (int j=1;j<=n;++j)
			if (sa[j]>=i+1)
				ps[sa[j]-i]=++cnt[rk[sa[j]-i]];
		for (int j=1;j<=length;++j) cnt[j]+=cnt[j-1];
		for (int j=1;j<=n;++j) sa[cnt[rk[j]-1]+ps[j]]=j;
		length=0;
		for (int j=1;j<=n;++j)
		{
			if (j==1||rk[sa[j]]!=rk[sa[j-1]]||(sa[j]+i<=(n<<1)?rk[sa[j]+i]:0)!=(sa[j-1]+i<=(n<<1)?rk[sa[j-1]+i]:0)) ++length;
			tmp[sa[j]]=length;
		}
		for (int j=1;j<=n;++j) rk[j]=tmp[j];
		for (int j=1;j<=length;++j) vis[j]=0;
	}
	for (int i=1;i<=n;++i)
	{
		h[rk[i]]=max(h[rk[i-1]]-1,0);
		if (rk[i]!=1)
		{
			while (i+h[rk[i]]<=n&&c[i+h[rk[i]]]==c[sa[rk[i]-1]+h[rk[i]]]) h[rk[i]]++;
		}
	}
	return;
}
int calc(int l,int r)
{
	int d=r-l+1,sl=rk[l],sr=rk[l];
	for (int i=lg[n];i>=0;--i)
		if (sr+(1<<i)<=n&&delta[sr][i]>=d)
			sr+=(1<<i);
	for (int i=lg[n];i>=0;--i)
		if (sl-(1<<i)>=1&&delta2[sl][i]>=d)
			sl-=(1<<i);
	return query(sr)-query(sl-1)-dp[r+1];
}
int main()
{
	for (int i=2;i<=N;++i) lg[i]=lg[i>>1]+1;
	cin>>s,n=s.length();
	for (int i=1;i<=n;++i) c[i]=s[i-1];
	build_SA();
	for (int i=2;i<=n;++i) delta[i-1][0]=delta2[i][0]=h[i];
	for (int i=1;i<=lg[n];++i)
	{
		for (int j=1;j<=n-(1<<i);++j) delta[j][i]=min(delta[j][i-1],delta[j+(1<<(i-1))][i-1]);
		for (int j=(1<<i)+1;j<=n;++j) delta2[j][i]=min(delta2[j][i-1],delta2[j-(1<<(i-1))][i-1]);
	}
	for (int i=n;i>=1;--i)
	{
		add(i,rk[i]),dque[++top]=i;
		while (top)
		{
			dp[i]=max(dp[i],calc(i,dque[top]));
			if (dp[i]<=dp[dque[top]+1]) top--;
			else break;
		}
	}
	printf("%d\n",dp[1]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 22636kb

input:

abbabbbbabbaaaaabbbaabaaaaaabbbaabbabababaabababaababaaaaaabaaabaaabbbbababaaabbbabababbbabbbaabaaababbbaabaabbaaabbababaaaaabbbaabaaabbaabaabaaabaaabaababaabbbbbbbbabbbbbabbbaabababbaababbbbbabbbbaaabbaabaabaaabbabbaaabbaaababaabbbaabbbaaaabbababbabaababababaaaabbaaaabaabaaaababaaabababbbaaabababbb...

output:

3798644

result:

wrong answer 1st lines differ - expected: '1281', found: '3798644'

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 1340ms
memory: 210088kb

input:

aaaaaaabbaaabbbbabbabbbababaabaaabaabbaaababaaaaaabbbbbaabbbabbbaabbabaababaababaabbbababbbabaaaaaaaaabaaaaabbbabbbbbabaaabaaaababbabbbbbbaabbbbbaababbbbababbbbbbbbbbbaaabbabbaababbaaaabbabaaabbaaabbbbaaababbbbbabbaababbaaababaaabbabaabbbbabbaaabbababbaabbaaaaaaaaaabababbbaaaababbabbbabbababbabbabbb...

output:

144328770

result:

wrong answer 1st lines differ - expected: '234567', found: '144328770'

Subtask #3:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 570ms
memory: 212080kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

1199805789

result:

wrong answer 1st lines differ - expected: '493827', found: '1199805789'

Subtask #4:

score: 0
Wrong Answer

Test #17:

score: 0
Wrong Answer
time: 165ms
memory: 61652kb

input:

bbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbabaabaaabbabbaaababaaabaaaabababbbbbbbaabbaaabbabbbbbabbbaaaaababbbaaabaabababbabbabababbabbabaaaaabaaaaaabbbabaabbbaaaabbabababaaababaabbbbbbbaaabbbabaabaaaabaabaababbaaaabababaabbbaaaababaaababbbbbbabbbbbbaabbabbaaa...

output:

724172716

result:

wrong answer 1st lines differ - expected: '43524', found: '724172716'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #2:

0%