@[Suspicious_spy](/user/1214977) 判一下边界应该就行,b数组可以用动态的
by Li_Feiy @ 2024-02-03 17:29:23
@[Suspicious_spy](/user/1214977)
```cpp
#include<iostream>
#include<cmath>
#include<cstring>
#define swift ios::sync_with_stdio(false),cin.tie(0),cin.tie(0);
using namespace std;
int a[3000];
int main(){
swift
int N;
cin>>N;
int min_index = 1,max_index = 1;
for(int i = 1;i <= N;++i){
cin>>a[i];
if(a[min_index] > a[i])
min_index = i;
if(a[max_index] < a[i])
max_index = i;
}
if(N == 1){
cout<<"Not jolly"<<endl;
exit(0);
}
if(a[max_index] - a[min_index] < N - 1){
cout<<"Not jolly"<<endl;
exit(0);
}
int * b = new int[N + 1];
for(int i = 1;i <= N - 1;++i){
b[i] = 0;
}
int temp;
for (int i = 1; i < N; ++i) {
temp = abs(a[i] - a[i + 1]);
if (temp >= N || temp == 0 || b[temp] == 1) {
cout << "Not jolly" << endl;
delete []b;
exit(0);
}
b[temp] = 1;
}
cout<<"Jolly"<<endl;
delete []b;
return 0;
}
```
by Li_Feiy @ 2024-02-03 17:31:05
@[Li_Feiy](/user/941431) 哦懂了,原来是temp在b数组中越界了,谢谢你?
by Suspicious_spy @ 2024-02-03 17:38:44
@[Li_Feiy](/user/941431) 我发的点赞表情变问号了,别介意哈哈
by Suspicious_spy @ 2024-02-03 17:42:46
@[Suspicious_spy](/user/1214977) :)
by Li_Feiy @ 2024-02-03 18:21:28