-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaekjoon_2632.java
More file actions
90 lines (66 loc) · 1.77 KB
/
baekjoon_2632.java
File metadata and controls
90 lines (66 loc) · 1.77 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class baekjoon_2632 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int M = Integer.parseInt(st.nextToken());
int N = Integer.parseInt(st.nextToken());
int[] a = new int[M+1];
int[] b = new int[N+1];
for(int i=1;i<=M;i++) {
a[i] = Integer.parseInt(br.readLine());
}
for(int i=1;i<=N;i++) {
b[i] = Integer.parseInt(br.readLine());
}
int[][] as = new int[a.length+1][a.length+1];
int[][] bs = new int[b.length+1][b.length+1];
int[] ac = new int[T+1];
int[] bc = new int[T+1];
for(int i=0;i<M;i++) {
for(int j=0;j<M-1;j++) {
int idx = (j + i) % M + 1;
as[i][j+1] = as[i][j] + a[idx];
// System.out.print(as[i][j+1] + " ");
if(as[i][j+1] <= T) {
ac[as[i][j+1]] += 1;
}
}
// System.out.println();
}
int sumA = 0;
for(int i=1;i<=M;i++) {
sumA += a[i];
}
if(sumA <= T) { ac[sumA] +=1; }
// System.out.println("===");
for(int i=0;i<N;i++) {
for(int j=0;j<N-1;j++) {
int idx = (j + i) % N + 1;
bs[i][j+1] = bs[i][j] + b[idx];
// System.out.print(bs[i][j+1] + " ");
if(bs[i][j+1] <= T) {
bc[bs[i][j+1]] += 1;
}
}
// System.out.println();
}
int sumB = 0;
for(int i=1;i<=N;i++) {
sumB += b[i];
}
if(sumB <= T) { bc[sumB] +=1; }
// System.out.println(Arrays.toString(ac));
// System.out.println(Arrays.toString(bc));
int cnt = 0;
for(int i=0;i<T;i++) {
cnt += ac[i] * bc[T-i];
}
cnt += ac[T];
cnt += bc[T];
System.out.println(cnt);
}
}