QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#868429#9738. Make It DivisiblexinlengweishangWA 1ms5968kbC++202.3kb2025-01-24 17:05:052025-01-24 17:05:05

Judging History

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

  • [2025-01-24 17:05:05]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5968kb
  • [2025-01-24 17:05:05]
  • 提交

answer

#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
pair<int,int> par[1000010];
int a[100010];
int b[100010];
vector<int> anss,ansb;
int gcd(int a,int b){
//	printf("%d %d\n",a,b);
	if(a<b) swap(a,b);
	if(b==0) return a;
	return a%b==0?b:gcd(b,a%b);
}
bool cmp(pair<int,int> a,pair<int,int> b){
	if(a.x!=b.x) return a.x<b.x;
	return a.y<b.y; 
}
void cal(int a,int b){
	for(int i=0;i<anss.size();i++){
//		printf("	test small: %d %d %d\n",i,(a+anss[i]-b),(b+anss[i]-b));
		if((a+anss[i])%(b+anss[i])==0) continue;
		else {
			anss.erase(anss.begin()+i);
			i--;
		}
	}
	for(int i=0;i<ansb.size();i++){
//		printf("	test big: %d %d %d\n",i,(a+ansb[i]-b),(b+ansb[i]-b));
		if((a+ansb[i])%(b+ansb[i])==0) continue;
		else {
			ansb.erase(ansb.begin()+i);
			i--;
		}
	}
}
void slove(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		par[i].x=a[i];
		par[i].y=i;
		b[i]=0;
	}
	sort(par+1,par+n+1,cmp);
	int gcdans=0;
	for(int i=2;i<=n;i++){
		gcdans=gcd(gcdans,par[i].x-par[i-1].x);
	}
//	printf("%d\n",gcdans);
	if(gcdans==0){
		long long w=k;
		long long ww=((w+1)*w)/2;
		printf("%d %lld\n",k,ww);
		return ;
	}
	else{
		for(int i=1;i*i<=gcdans;i++){
			if(!(gcdans%i)){
//				printf("   %d\n",i);
				if(i>par[1].x)
				anss.push_back(i-par[1].x);
				if(gcdans/i>par[1].x)
				ansb.push_back(gcdans/i-par[1].x);
			}
		}
	}
//	printf("111\n");
	b[0]=1;
	b[n+1]=1;
	for(int i=1;i<=n;i++){
		int t=par[i].y;
		b[t]=1;
		int l=t,r=t;
//		printf("i=%d t=%d\n",i,t);
		while(!b[l-1]){
			if(a[l-1]!=par[i].x)
			cal(a[l-1],par[i].x);
			l--;
		} 
		while(!b[r+1]){
			if(a[r+1]!=par[i].x)
			cal(a[r+1],par[i].x);
			r++;
		}
//		for(int w=0;w<anss.size();w++){
//			printf("	%d %d %d\n",t,w,anss[w]);
//		}
//		for(int w=0;w<ansb.size();w++){
//			printf("	%d %d %d\n",t,w,ansb[w]);
//		}
		if(anss.empty()&&ansb.empty()){
			printf("0 0\n");
			return ;
		}
	}
	printf("%d ",anss.size()+ansb.size());
	long long aans=0;
	for(int i=0;i<anss.size();i++){
		aans+=anss[i];
	}
	for(int i=0;i<ansb.size();i++){
		aans+=ansb[i];
	}
	printf("%lld\n",aans);
	return ;
}
int main(){
	int T;
	scanf("%d",&T);
	while(T--) slove();
	return 0;
}
/*
3
5 10
7 79 1 7 1
2 1000000000
1 2
1 100
1000000000
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
5 10
7 79 1 7 1
2 1000000000
1 2
1 100
1000000000

output:

3 8
0 0
100 5050

result:

ok 3 lines

Test #2:

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

input:

4
201 1000000000
1 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5...

output:

0 0
0 0
0 0
0 0

result:

ok 4 lines

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3840kb

input:

500
4 1000000000
8 14 24 18
4 1000000000
17 10 18 14
4 1000000000
6 17 19 19
4 1000000000
15 14 15 25
4 1000000000
16 16 5 25
4 1000000000
4 30 20 5
4 1000000000
11 4 23 9
4 1000000000
14 25 13 2
4 1000000000
18 18 1 15
4 1000000000
22 22 22 28
4 1000000000
15 17 17 10
4 1000000000
22 14 13 25
4 100...

output:

0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
...

result:

wrong answer 78th lines differ - expected: '2 4', found: '3 5'