70分优先队列 RE 求解
查看原帖
70分优先队列 RE 求解
1041348
ZMS114514楼主2024/9/1 10:17
#include<bits/stdc++.h>
using namespace std;
priority_queue<int> q;
int n,a[6666];
int main() 
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++) {
			q.push(a[i] % a[j]),q.push(a[j] % a[i]);
		}
	}
	int k=q.top();
	while(q.size()) {
		if(q.top()!= k) {
			cout<<q.top();
			return 0;
		}
		q.pop();
	}
	cout<<-1;
	return 0;
}
2024/9/1 10:17
加载中...