QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#199922#7345. Circular ShiftPhantomThreshold#WA 24ms202984kbC++201.6kb2023-10-04 14:40:232023-10-04 14:40:23

Judging History

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

  • [2023-10-04 14:40:23]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:202984kb
  • [2023-10-04 14:40:23]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;

const int maxn = 610000;

string S;
int sum[maxn][26];
struct SAM
{
	int rt,tot,last;
	int son[maxn][26],par[maxn],len[maxn],ri[maxn];
	int newnode()
	{
		++tot;
		par[tot]=len[tot]=0;
		memset(son[tot],0,sizeof son[tot]);
		return tot;
	}
	void init()
	{
		rt=tot=last=0;
		rt=last=newnode();
	}
	void extend(const int w,const int r)
	{
		int p=last,np=newnode();
		len[np]=len[p]+1;
		
		while(p&&!son[p][w]) son[p][w]=np,p=par[p];
		if(!p) par[np]=rt;
		else
		{
			int q=son[p][w];
			if(len[q]==len[p]+1) par[np]=q;
			else
			{
				int nq=newnode(); len[nq]=len[p]+1;
				memcpy(son[nq],son[q],sizeof son[nq]);
				par[nq]=par[q];
				par[q]=par[np]=nq;
				
				while(p&&son[p][w]==q) son[p][w]=nq,p=par[p];
			}
		}
		last=np;
		ri[np]=r;
	}
	int cal()
	{
		for(int i=tot;i>=2;i--) if(ri[i])
		{
			int ff=par[i];
			ri[ff]=ri[i];
		}
		
		int ret=0;
		for(int i=2;i<=tot;i++)
		{
			int ff=par[i];
			if(len[i]-len[ff]>1)
			{
				for(int j=0;j<26;j++) if(son[i][j])
					ret+= sum[ri[i]-len[ff]-1][j]-sum[ri[i]-len[i]][j];
			}
			for(int j=0;j<26;j++) if(son[ff][j] && S[ri[i]-len[ff]]-'a'==j)
				ret+=1;
		}
		return ret;
	}
}tr;

int n;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>S; n=S.size(); S=' '+S;
	
	for(int i=1;i<=n;i++)
	{
		for(int c=0;c<26;c++) sum[i][c]=sum[i-1][c];
		sum[i][S[i]-'a']++;
	}
	
	tr.init();
	for(int i=1;i<=n;i++) 
	{
		tr.extend(S[i]-'a',i);
	}
	cout<<tr.cal()<<'\n';
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 9928kb

input:

abaac

output:

7

result:

ok 1 number(s): "7"

Test #2:

score: 0
Accepted
time: 0ms
memory: 9740kb

input:

aaa

output:

3

result:

ok 1 number(s): "3"

Test #3:

score: 0
Accepted
time: 0ms
memory: 9764kb

input:

a

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 9676kb

input:

z

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 1ms
memory: 9628kb

input:

aa

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 1ms
memory: 9744kb

input:

az

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 1ms
memory: 9672kb

input:

za

output:

2

result:

ok 1 number(s): "2"

Test #8:

score: 0
Accepted
time: 1ms
memory: 9676kb

input:

zz

output:

2

result:

ok 1 number(s): "2"

Test #9:

score: 0
Accepted
time: 1ms
memory: 9708kb

input:

abc

output:

3

result:

ok 1 number(s): "3"

Test #10:

score: 0
Accepted
time: 1ms
memory: 9896kb

input:

aab

output:

3

result:

ok 1 number(s): "3"

Test #11:

score: 0
Accepted
time: 1ms
memory: 9748kb

input:

baa

output:

3

result:

ok 1 number(s): "3"

Test #12:

score: 0
Accepted
time: 1ms
memory: 9740kb

input:

dbda

output:

5

result:

ok 1 number(s): "5"

Test #13:

score: 0
Accepted
time: 1ms
memory: 9744kb

input:

dacc

output:

4

result:

ok 1 number(s): "4"

Test #14:

score: 0
Accepted
time: 1ms
memory: 9632kb

input:

cdaca

output:

6

result:

ok 1 number(s): "6"

Test #15:

score: 0
Accepted
time: 1ms
memory: 9768kb

input:

cddcc

output:

8

result:

ok 1 number(s): "8"

Test #16:

score: 0
Accepted
time: 1ms
memory: 9700kb

input:

adcbdb

output:

7

result:

ok 1 number(s): "7"

Test #17:

score: 0
Accepted
time: 1ms
memory: 9696kb

input:

cccccc

output:

6

result:

ok 1 number(s): "6"

Test #18:

score: 0
Accepted
time: 1ms
memory: 9960kb

input:

ccdcabb

output:

9

result:

ok 1 number(s): "9"

Test #19:

score: 0
Accepted
time: 1ms
memory: 9728kb

input:

bcbddca

output:

8

result:

ok 1 number(s): "8"

Test #20:

score: 0
Accepted
time: 1ms
memory: 9760kb

input:

cadababb

output:

11

result:

ok 1 number(s): "11"

Test #21:

score: 0
Accepted
time: 1ms
memory: 9960kb

input:

bdddcbbc

output:

11

result:

ok 1 number(s): "11"

Test #22:

score: 0
Accepted
time: 1ms
memory: 9972kb

input:

acdaabcdb

output:

10

result:

ok 1 number(s): "10"

Test #23:

score: 0
Accepted
time: 1ms
memory: 9748kb

input:

abcabdcad

output:

11

result:

ok 1 number(s): "11"

Test #24:

score: 0
Accepted
time: 1ms
memory: 9896kb

input:

bccbccccda

output:

17

result:

ok 1 number(s): "17"

Test #25:

score: 0
Accepted
time: 1ms
memory: 9768kb

input:

bbdddadcab

output:

14

result:

ok 1 number(s): "14"

Test #26:

score: 0
Accepted
time: 8ms
memory: 142788kb

input:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

300000

result:

ok 1 number(s): "300000"

Test #27:

score: 0
Accepted
time: 19ms
memory: 141836kb

input:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

300000

result:

ok 1 number(s): "300000"

Test #28:

score: 0
Accepted
time: 15ms
memory: 202984kb

input:

yxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

300000

result:

ok 1 number(s): "300000"

Test #29:

score: 0
Accepted
time: 24ms
memory: 140672kb

input:

abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmn...

output:

299988

result:

ok 1 number(s): "299988"

Test #30:

score: 0
Accepted
time: 20ms
memory: 173680kb

input:

cacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacacaca...

output:

5625225001

result:

ok 1 number(s): "5625225001"

Test #31:

score: -100
Wrong Answer
time: 0ms
memory: 9820kb

input:

acaacacbcacabbaaabbbbcbaabcccabbbabaabbbccaabcbbbcaabbbbcbbcaacabaccbbacbaccacbbbabaccbaabbbccaaccbcbbaabbccccca

output:

2022

result:

wrong answer 1st numbers differ - expected: '2024', found: '2022'