#include <cstdio>
#include <iostream>
#include <vector>
#include<cmath>
using namespace std;
bool isvalid(vector<int> v)
{
for (int i = 0; i < v.size(); i++)
{
for (int j = 0; j < i; j++)
{
if (v[i] == v[j] || abs(v[j] - v[i]) == abs(i - j))
{
return false;
}
}
}
return true;
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
vector<int> v;
int m;
scanf("%d",&m);
for(int i = 0; i < m; i++)
{
int a;
scanf("%d",&a);
v.push_back(a);
}
if(isvalid(v))
printf("YES\n");
else
printf("NO\n");
}
}
综合了两位大佬的答案:(柳神写法时间会偏长一些)
https://blog.csdn.net/Hickey_Chen/article/details/81095025
https://blog.csdn.net/liuchuo/article/details/62232899