File size: 1,220 Bytes
c4b0eef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
/*
Problem: 10038 - Jolly Jumpers
Link   : https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=979

Solution by: Mohamed Hisham El-Banna

Gmail   : [email protected]
Github  : www.github.com/Mhmd-Hisham
LinkedIn: www.linkedin.com/in/Mhmd-Hisham
*/

using namespace std;

typedef signed long long ll;
typedef unsigned long long ull;

#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int N;
int freq[3001], a, b;

int main () {
    fastio;
    
    while ( cin >> N && !cin.eof() ){
        memset(freq, 0, sizeof(freq));
        
        bool isJolly = true;

        cin >> a;
        for (int i = 1; i < N; ++i){
            cin >> b;
            
            if (abs(a-b) >= N) isJolly = false;
            else freq[abs(a-b)]++;
            
            a = b;
        }
        
        for (int i = 1; i < N; ++i)
            isJolly &= freq[i];
              
        cout << (isJolly? "Jolly" : "Not jolly") << '\n';
        
    }

    return 0;
}
/*
Sample input:-
-----------------
4 1 4 2 3
5 1 4 2 -1 6

Sample output:-
-----------------


Resources:-
-------------

Explanation:
---------------

*/