调了几个小时555
record: https://www.luogu.com.cn/record/201530666
#16 Time Limit Exceeded. 1.20s/5.54MB
My Code:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e3, MAXS = 1e6;
//快读
inline int read()
{
static char c;
while (c = getchar(), !isdigit(c))
;
int res = c - 48;
while (c = getchar(), isdigit(c))
res = (res << 3) + (res << 1) + c - 48;
return res;
}
int n, s[MAXN + 1], d[MAXN * MAXN + 1], siz, maxb, i, j, ptr;
bool b[MAXS + 1], flag;
int main()
{
n = read();
for (i = 1; i <= n; ++i)
{
s[i] = read();
for (j = 1; j < i; ++j)
b[abs(s[i] - s[j])] = true, maxb = max(maxb, abs(s[i] - s[j]));
}
for (i = 1; i <= maxb; ++i)
if (b[i])
d[siz++] = i;
for (ptr = 0, i = n, flag = false; !flag; ++i)
{
flag = true;
while (d[ptr++] < i)
;
for (j = --ptr; j < siz && flag; ++j)
if (!(d[j] % i))
flag = false;
}
cout << i - 1 << endl;
return 0;
}
大佬教教这位可怜的蒟蒻吧