QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#758683#9738. Make It Divisiblefhq_treap#WA 1ms3804kbC++231.1kb2024-11-17 19:21:082024-11-17 19:21:10

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-17 19:21:10]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3804kb
  • [2024-11-17 19:21:08]
  • 提交

answer

#include<iostream>
#include<vector>
#include<algorithm>
using std::cin,std::cout;
int n,k,b[50010],ls[50010],rs[50010];
int s[50010],*tp=s;
void solve(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>b[i];
	if(std::all_of(b+1,b+n+1,[](int x){return x==b[1];})){
		cout<<k<<' '<<(k+1ll)*k/2<<'\n';
		return;
	}
	b[0]=-1;
	*tp=0;
	for(int i=1;i<=n;i++){
	    while(b[*tp]>=b[i])ls[i]=*tp--;
	    if(tp!=s)rs[*tp]=i;
	    *++tp=i;
	}
	std::vector<int> xs;
	for(int i=1;i<=n;i++){
		int x=0;
		if(ls[i]&&b[ls[i]]!=b[i]) x=ls[i];
		if(rs[i]&&b[rs[i]]!=b[i]) x=rs[i];
		if(x){
			int u=b[x]-b[i];
			for(int r=1;r*r<=u;r++)if(u%r==0){
				if(b[i]<r) xs.push_back(r-b[i]);
				if(b[i]<u/r) xs.push_back(u/r-b[i]);
			}
			break;
		}
	}
	int ans1=0;
	long long ans2=0;
	for(auto x:xs){
		int book=1;
		for(int i=1;book&&i<=n;i++){
			if(ls[i]&&(b[ls[i]]-b[i])%(b[i]+x)!=0) book=0;
			if(rs[i]&&(b[rs[i]]-b[i])%(b[i]+x)!=0) book=0;
		}
		if(book) ans1++,ans2+=x;
	}
	cout<<ans1<<' '<<ans2<<'\n';
}
int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3544kb

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: 0ms
memory: 3804kb

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: 3576kb

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: '0 0'