This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Problem : 10038 - Jolly Jumpers. | |
* Author : Md.Mehadi Hasan Menon. | |
* Status : Accepted. | |
* Date : 28.11.2014. | |
**/ | |
#include <iostream> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <algorithm> | |
using namespace std; | |
int a[3005], b[3005]; | |
int main() | |
{ | |
int i, j, n, flag; | |
while(scanf("%d", &n) != EOF) | |
{ | |
for(i = 0; i < n; i++) | |
{ | |
scanf("%d", &a[i]); | |
} | |
j = 0; | |
for(i = 0; i < n-1; i++) | |
{ | |
b[j++] = abs(a[i] - a[i+1]); | |
} | |
sort(b, b + j); | |
flag = 0; | |
if(n == 1) | |
flag = 0; | |
else if(b[0] != 1 || b[j-1] != n-1) | |
flag = 1; | |
else | |
{ | |
for(i = 0; i < j-1; i++) | |
{ | |
if(b[i+1] - b[i] != 1) | |
{ | |
flag = 1; | |
break; | |
} | |
} | |
} | |
if(flag == 1) | |
printf("Not jolly\n"); | |
else | |
printf("Jolly\n"); | |
} | |
return 0; | |
} |
Comments
Post a Comment