-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbee1472.cpp
More file actions
56 lines (44 loc) · 1.04 KB
/
Copy pathbee1472.cpp
File metadata and controls
56 lines (44 loc) · 1.04 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
/**
* Contest : Beecrowd
* Problem : Triângulos
* Link : https://judge.beecrowd.com/pt/problems/view/1472
* Time : O(N logN)
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
int n;
void solve () {
vector<int> x(n+1);
set<int> points, used;
points.insert(0);
for (int i = 1; i <= n; ++i) {
cin >> x[i];
x[i] += x[i-1];
points.insert(x[i]);
}
int total = x.back();
if (total % 3) {
cout << "0\n";
return;
}
int side = total/3, cnt = 0;
for (int i = 0; i < n; ++i) {
int p1 = x[i];
int p2 = (p1+side) % total;
int p3 = (p2+side) % total;
int p4 = (p3+side) % total; // p4 deve ser igual p1
if (!points.count(p2) || !points.count(p3)) continue;
if (used.count(p1) || used.count(p2) || used.count(p3)) continue;
// cerr << p1 << ' ' << p2 << ' ' << p3 << ' ' << p4 << '\n';
used.insert(p1);
cnt++;
}
cout << cnt << '\n';
}
int main() {
fastio
while (cin >> n) solve();
return 0;
}