File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+ import java .util .*;
3
+
4
+ class Main {
5
+ public static void main (String [] args ) throws Exception {
6
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
7
+ BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System .out ));
8
+ int n = Integer .parseInt (br .readLine ());
9
+ int [] arr = new int [n + 1 ];
10
+ StringTokenizer st = new StringTokenizer (br .readLine ());
11
+ for (int i = 1 ; i <= n ; i ++) {
12
+ arr [i ] = Integer .parseInt (st .nextToken ());
13
+ arr [i ] += arr [i - 1 ];
14
+ }
15
+
16
+ long [] dp = new long [4 ];
17
+ dp [0 ] = 1 ;
18
+
19
+ long answer = 0 ;
20
+ if (arr [n ] == 0 ) {
21
+ long count = 0 ;
22
+ for (int i = 1 ; i <= n ; i ++) {
23
+ if (arr [i ] == 0 ) {
24
+ count ++;
25
+ }
26
+ }
27
+ answer = (count - 1 ) * (count - 2 ) * (count - 3 ) / 6 ;
28
+ } else if (arr [n ] % 4 == 0 ) {
29
+ int target = arr [n ] / 4 ;
30
+ for (int i = 1 ; i <= n ; i ++) {
31
+ int count = arr [i ] / target ;
32
+ if (arr [i ] % target == 0 && count > 0 && count < 4 ) {
33
+ dp [count ] += dp [count - 1 ];
34
+ }
35
+ }
36
+ answer = dp [3 ];
37
+ }
38
+
39
+ bw .write (Long .toString (answer ));
40
+ bw .flush ();
41
+ bw .close ();
42
+ }
43
+ }
You can’t perform that action at this time.
0 commit comments