-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorderedproblemset.cpp
More file actions
61 lines (53 loc) · 1.35 KB
/
orderedproblemset.cpp
File metadata and controls
61 lines (53 loc) · 1.35 KB
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
/*
* Author: Maanas Karwa
* It is ok to share my code anonymously for educational purposes
* */
#include <bits/stdc++.h>
using namespace std;
int n, difficulties[50];
int mx(int l, int r) { //helper func, find max in given range inclusive
if (l < 0)
l = 0;
if (r >= n)
r = n - 1;
int mx = -1;
for (int i = l; i <= r; i++)
mx = max(mx, difficulties[i]);
return mx;
}
int mn(int l, int r) { //helper func, find min in given range inclusive
if (l < 0)
l = 0;
if (r >= n)
r = n - 1;
int mn = 1e9;
for (int i = l; i <= r; i++)
mn = min(mn, difficulties[i]);
return mn;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin.exceptions(std::istream::failbit);
cin >> n;
for (int i = 0; i < n; i++)
cin >> difficulties[i];
bool valueExists = false;
for (int k = 2; k <= n; k++) {
if (n % k == 0) {
int elementsPerSet = n / k;
bool valid = true;
for (int section = 1; section < k && valid; section++)
//if (max of prev section > min of current section) invalid
if (mx((section - 1) * elementsPerSet, section * elementsPerSet - 1) >
mn(section * elementsPerSet, (section + 1) * elementsPerSet - 1))
valid = false;
if (valid) {
valueExists = true;
cout << k << "\n";
}
}
}
if (!valueExists)
cout << "-1\n";
}