-
Notifications
You must be signed in to change notification settings - Fork 6
/
BusStation.cpp
41 lines (34 loc) · 1006 Bytes
/
BusStation.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
#include <cstdio>
#include <vector>
#include <algorithm>
int main(){
long n; scanf("%ld", &n);
std::vector<long> a(n);
long total(0), most(0);
for(long p = 0; p < n; p++){
scanf("%ld", &a[p]);
total += a[p];
most = (most > a[p]) ? most : a[p];
}
std::vector<long> div;
for(long p = 1; p * p <= total; p++){
if(total % p != 0){continue;}
div.push_back(p);
if(p * p != total){div.push_back(total / p);}
}
std::vector<long> v;
for(long p = 0; p < div.size(); p++){
long cand = div[p];
if(cand < most){continue;}
long cur(0), possible(true);
for(long k = 0; k < n; k++){
cur += a[k];
if(cur == cand){cur = 0;}
else if(cur > cand){possible = false; break;}
}
if(possible && (cur == 0)){v.push_back(cand);}
}
sort(v.begin(), v.end());
for(long p = 0; p < v.size(); p++){printf("%ld ", v[p]);}; puts("");
return 0;
}