-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp10038 - Jolly Jumpers.cpp
47 lines (36 loc) · 1002 Bytes
/
p10038 - Jolly Jumpers.cpp
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
#include <iostream>
#include <vector>
#include <sstream>
#include <numeric>
#include <algorithm>
#include <functional>
using namespace std;
int main(int argc, const char* argv[]) {
ios::sync_with_stdio(false);
string buf;
while (getline(cin, buf)) {
vector<int> nums;
stringstream ss(buf);
int size, input;
// seqence size
ss >> size;
// get numbers
while (ss >> input)
nums.push_back(input);
// create bitmap
vector<bool> bitmap;
bitmap.resize(size, false);
bitmap[0] = true;
// fill bitmap
for (int i = 0; i < size - 1; i++) {
int diff = abs(nums[i] - nums[i + 1]);
if(diff <= size - 1)
bitmap[diff] = true;
}
// check bitmap
string result = find(bitmap.begin(), bitmap.end(), false)
== bitmap.end() ? "Jolly" : "Not jolly";
cout << result << endl;
}
return 0;
}