-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumberofways.cpp
More file actions
50 lines (37 loc) · 750 Bytes
/
Copy pathnumberofways.cpp
File metadata and controls
50 lines (37 loc) · 750 Bytes
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
#include <iostream>
#include <vector>
#define ll long long
int main()
{
int n,l;
std::cin>>n;
std::vector<int> arr(n+1);
std::vector<ll> sum(n+1);
sum[0] = 0;
for (size_t i = 1; i <= n; i++)
{
std::cin>>l;
arr[i] = l;
sum[i] = sum[i-1] + l;
}
if ( sum[n]%3 != 0 ){
std::cout<<0<<std::endl;
return 0;
}
ll c1=0;
ll ways = 0;
for (size_t i = 1; i <= n; i++)
{
if( sum[i] == 2*(sum[n]/3) ){
if(! (sum[n] == 0 && i == n ) ){
ways+= c1;
}
}
if( sum[i] == sum[n]/3 )
{
c1++;
}
}
std::cout<<ways<<std::endl;
return 0;
}