-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathcran04.java
37 lines (32 loc) · 1.08 KB
/
cran04.java
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
import java.io.*;
import java.util.*;
public class cran04 {
private static BufferedReader in;
private static PrintWriter out;
public static void main(String[] args) throws IOException {
in = new BufferedReader(new InputStreamReader (System.in));
out = new PrintWriter(System.out, true);
int T = Integer.parseInt (in.readLine());
StringTokenizer st;
while (T-- > 0) {
st = new StringTokenizer (in.readLine());
int N = Integer.parseInt (st.nextToken());
int K = Integer.parseInt (st.nextToken());
char [] s = in.readLine().toCharArray();
long res = 0;
int [] count = new int [N + 1];
int ccount = 0;
count [0]++;
for (char c : s) {
if (c == '1') ccount++;
if (ccount >= K) {
res += count [ccount - K];
}
count [ccount]++;
}
out.println (res);
}
out.close();
System.exit(0);
}
}