求助!70分最后三个点TLE!
查看原帖
求助!70分最后三个点TLE!
526922
coool楼主2023/8/2 20:00
#include <bits/stdc++.h>
using namespace std;

int n;
int arr[1000005], ans[1000005];
int t;

set<int> s;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &arr[i]);

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {

            if (i == j)
                t = 0;

            else
                t = arr[i] % arr[j];

            s.insert(t); // 依次取模添加进set自动去重
        }
    }

    if (s.size() >= 2)
    {
        int top = 1;
        for (auto i : s) // 遍历集合
        {
            ans[++top] = i;
            // cout << i << " ";
        }

        printf("%d", ans[top - 1]);
    }

    else
        printf("-1");

    return 0;
}
2023/8/2 20:00
加载中...