求助,蜜汁UKE
查看原帖
求助,蜜汁UKE
415961
Luo_gu_ykc楼主2022/5/15 10:15

Vjudge测评AC,你谷评测UKE求调 qwq

#include<bits/stdc++.h>

using namespace std;

const int N = 105;
 
int v[N], a[N], x, n, num;	

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> x;
		if(!v[x]){
			a[++num] = x;
			v[x] = 1; //
		}
	}
	sort(a + 1, a + 1 + num);
	if(num == 1){
		cout << 0;
		return 0;
	} else if(num == 2){
		if((a[2] - a[1]) % 2 == 0){
			cout << (a[2] - a[1]) / 2;
		} else {
			cout << a[2] - a[1]; 
		}
		return 0;
	} else if(num == 3){
		if((a[3] - a[2]) == (a[2] - a[1])){
			cout << a[2] - a[1];
		} else {
			cout << "-1";
		}
		return 0;
	} else if(num >= 4){
		cout << "-1";
		return 0;
	} 
    return 0;
}

2022/5/15 10:15
加载中...