#P16269. [蓝桥杯 2026 省 Java B 组] 量子态叠加计数器

[蓝桥杯 2026 省 Java B 组] 量子态叠加计数器

Problem Description

A quantum laboratory recorded the states of NN qubits at times 1,2,…,T1, 2, \dots, T. Each state value is 00 or 11.

For any qubit and any time interval [L,R][L, R] (1≤L≤R≤T1 \leq L \leq R \leq T), if the number of times the qubit’s state is 11 within the interval is exactly KK, then we say the qubit produces one valid superposition in this interval.

Now, please count: among all qubits and all time intervals, the total number of valid superpositions.

Input Format

The first line contains three integers N,T,KN, T, K, representing the number of qubits, the number of time points, and the target count.

The next NN lines each contain TT integers (00 or 11). The ii-th line represents the state sequence of the ii-th qubit over all time points.

Output Format

Output one line with one integer, indicating the total number of valid superpositions.

3 5 2
1 0 1 0 1
0 1 1 0 0
1 1 0 0 1
14
2 4 1
1 0 0 1
0 0 0 0
6
1 6 3
1 1 0 1 1 0
3
1 3 0
0 0 0
6

Hint

Sample Explanation 1

For the 1st qubit 1 0 1 0 11\ 0\ 1\ 0\ 1, the intervals that satisfy the condition are: [1,3][1,3], [1,4][1,4], [2,5][2,5], [3,5][3,5]. There are 44 intervals in total.

For the 2nd qubit 0 1 1 0 00\ 1\ 1\ 0\ 0, the intervals that satisfy the condition are: [1,3][1,3], [1,4][1,4], [1,5][1,5], [2,3][2,3], [2,4][2,4], [2,5][2,5]. There are 66 intervals in total.

For the 3rd qubit 1 1 0 0 11\ 1\ 0\ 0\ 1, the intervals that satisfy the condition are: [1,2][1,2], [1,3][1,3], [1,4][1,4], [2,5][2,5]. There are 44 intervals in total.

Therefore, the total count is 4+6+4=144 + 6 + 4 = 14.

Sample Explanation 2

For the 1st qubit 1 0 0 11\ 0\ 0\ 1, the intervals that contain exactly 11 state equal to 11 are: [1,1][1,1], [1,2][1,2], [1,3][1,3], [2,4][2,4], [3,4][3,4], [4,4][4,4]. There are 66 intervals in total.

For the 2nd qubit 0 0 0 00\ 0\ 0\ 0, there is no state equal to 11 in any interval, so there are no intervals that contain exactly 11 state equal to 11.

So the answer is 6+0=66 + 0 = 6.

Sample Explanation 3

The only qubit is 1 1 0 1 1 01\ 1\ 0\ 1\ 1\ 0.

The intervals that contain exactly 33 states equal to 11 are: [1,4][1,4], [2,5][2,5], [2,6][2,6]. There are 33 intervals in total.

Sample Explanation 4

The only qubit has state 00 at all time points.

When K=0K = 0, we need to count the cases where there are exactly 00 states equal to 11 in the interval, i.e., intervals where all values are 00.

When T=3T = 3, there are 3×42=6\frac{3 \times 4}{2} = 6 intervals in total, and all of them satisfy the condition, so the answer is 66.

Constraints

For 30%30\% of the testdata, N≤10N \leq 10, T≤100T \leq 100.

For 60%60\% of the testdata, N≤50N \leq 50, T≤500T \leq 500.

For all testdata, 1≤N≤2001 \leq N \leq 200, 1≤T≤10001 \leq T \leq 1000, 0≤K≤T0 \leq K \leq T. It is guaranteed that all state values in the input are either 00 or 11.

Translated by ChatGPT 5