QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#378350#8571. Palworlducup-team1004#WA 1745ms23324kbC++142.0kb2024-04-06 11:48:492024-04-06 11:48:50

Judging History

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

  • [2024-04-06 11:48:50]
  • 评测
  • 测评结果:WA
  • 用时:1745ms
  • 内存:23324kb
  • [2024-04-06 11:48:49]
  • 提交

answer

#include<bits/stdc++.h>
#define mid ((l+r)>>1)
using namespace std;
typedef long long ll;
const int p1=1e9+7,p2=1e9+9,N=3e5+10;
struct hsh{
	ll a,b;
	hsh (ll x=0,ll y=0){a=x,b=y;}
	hsh operator +(int c){return hsh((a+c)%p1,(b+c)%p2);}
}h1[N],h2[N],K[N];
bool operator ==(hsh a,hsh b){return a.a==b.a&&a.b==b.b;}
hsh operator -(hsh a,hsh b){return hsh((a.a-b.a+p1)%p1,(a.b-b.b+p2)%p2);}
hsh operator *(hsh a,hsh b){return hsh(a.a*b.a%p1,a.b*b.b%p2);}
int T,n,k,ans;
char str[N];
hsh calc1(int l,int r){return h1[r]-h1[l-1]*K[r-l+1];}
hsh calc2(int l,int r){return h2[l]-h2[r+1]*K[r-l+1];}
void work(int x,int y,int cur)
{
	ans=max(ans,cur);
	int p=(ans-cur)/2+1;
	if(x-p+1<1||y+p-1>n||!(calc1(x-p+1,x)==calc2(y,y+p-1))) return;
	int l=p+1,r=min(x,n-y+1);
	while(l<r)
		if(calc1(x-mid+1,x)==calc2(y,y+mid-1)) l=mid+1;
		else r=mid;
	ans=max(ans,(l-1)*2+cur);
}
int main()
{
	scanf("%d",&T);
	K[0]=hsh(1,1),K[1]=hsh(131,131);
	for(int i=2;i<N;i++) K[i]=K[i-1]*K[1];
	while(T--)
	{
		scanf("%d%d%s",&n,&k,str+1);
		h1[0]=h2[n+1]=hsh(0,0),ans=k+min(n,k);
		for(int i=1;i<=n;i++) h1[i]=h1[i-1]*K[1]+str[i];
		for(int i=n;i;i--) h2[i]=h2[i+1]*K[1]+str[i];
		vector<pair<int,int>> v;
		vector<int> v1;
		for(int i=1;i<=n;i++)
		{
			int l=1,r=min(i,n-i+1);
			while(l<r)
				if(calc1(i-mid,i)==calc2(i,i+mid)) l=mid+1;
				else r=mid;
			ans=max(ans,2*l-1);
			v.push_back({i-l,i+l});
		}
		for(int i=1;i<n;i++)
		{
			int l=0,r=min(i,n-i+1);
			while(l<r)
				if(calc1(i-mid,i)==calc2(i+1,i+mid+1)) l=mid+1;
				else r=mid;
			ans=max(ans,l*2+k);
			v.push_back({i-l,i+l+1});
		}
		shuffle(v.begin(),v.end(),mt19937(0));
		for(auto x:v)
		{
			int len=x.second-x.first-1;
			for(int i=1;i<=k&&x.second+i<=n+1;i++) work(x.first,x.second+i,len+2*i);
			for(int i=1;i<=k&&x.first-i>=0;i++) work(x.first-i,x.second,len+2*i);
		}
		for(int i=1;i<=n;i++) v1.push_back(i);
		shuffle(v1.begin(),v1.end(),mt19937(0));
		for(auto x:v1)
			for(int i=1;i<=k&&x+i-1<=n;i++) work(x-1,x+i,k+i);
		printf("%d\n",ans);
	}
}

详细

Test #1:

score: 100
Accepted
time: 5ms
memory: 17900kb

input:

4
1 3
a
4 1
icpc
4 2
icpc
8 4
icecream

output:

4
5
5
11

result:

ok 4 number(s): "4 5 5 11"

Test #2:

score: 0
Accepted
time: 1187ms
memory: 23324kb

input:

1
200000 66
jsmwjmibgkjvdscqllsxpaxiycmpauhnzschbivtqbjfrxrqvhvfbqecozjewqqpwdfbeqppjkgxhbnniopkptkygspcdswhwadfwhnzovvpshgcdukrupeztkpxwhmctaquqbxtidzbbxsyuaeikuldaoeudletrsmqptaejibkymsjhmwykqsjdvvdaqwelrcpxwrwhuvodipjniowfofbjktkdezwqqbvwsppsmpilntmdmlxgkaxymnugmmcsljkjzjuudnllydwdwwanadynsoiolso...

output:

141

result:

ok 1 number(s): "141"

Test #3:

score: 0
Accepted
time: 1745ms
memory: 22772kb

input:

1
200000 100
qhiaajzxinenucrnfffumuhnovpuwcnojbhsktztapgyivmfqrlntwazwnfetwqieckxcnkskpidltiydfoveaucckximydxxfbiwbdufmbhywqkflyqxbijakadqkzftlciccbpnldsqhtjxuxnvkusvizavuyfhdroiuominebadhfqzrpjnzpgyvkejfwmueiltyeqpvwrkanqknyacqganbszktocfuvvsfrboaennwpaabfdnaurvvurysrijnfaonesihbhrrvbvyhpbremsuhhbc...

output:

209

result:

ok 1 number(s): "209"

Test #4:

score: -100
Wrong Answer
time: 101ms
memory: 17848kb

input:

10000
21 7
fhcjhdjcfbfbdeeheibhg
18 8
hccgjfaadefhjhcijc
15 7
ahefiiheaigjiid
15 3
fgjjebidbfgbdij
15 5
jccebbgjbhifjhb
20 2
hcbddhibgfccjjcfebcc
19 1
ehbdgiicchijebidbcd
20 8
gbcfghefhbjggecdhcbj
17 2
jjaeaccjbcfiehfdd
23 4
iafjedfbebbhcfgfjbehdaf
22 1
jgiiiaacehcbaiehfggcfi
17 2
jefbbfigfhbhfcici
...

output:

17
21
17
11
13
9
6
18
9
11
6
9
22
8
21
23
5
23
7
16
9
23
25
11
17
12
9
5
20
5
23
12
7
13
16
17
21
21
21
12
16
21
21
8
9
11
21
15
5
24
13
7
21
13
11
8
7
19
25
7
8
12
13
22
15
14
7
15
7
20
15
13
11
15
5
11
23
17
17
19
15
7
19
17
25
13
23
10
17
21
9
21
7
23
21
13
16
7
14
10
13
10
9
11
7
21
15
19
11
23
...

result:

wrong answer 190th numbers differ - expected: '9', found: '7'