PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000042. Đếm đoạn con có nhiều số 1 hơn số 0 (Count Subarrays With More Ones Than Zeros)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm đoạn con có nhiều số 1 hơn số 0 (Count Subarrays With More Ones Than Zeros)
Count Subarrays With More Ones Than Zeros
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given a binary array, count contiguous subarrays containing strictly more ones than zeros. Print the result modulo .
Input
The first line is ; the second line contains binary digits (space-separated).
Output
Print the answer modulo .
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
5
0 1 1 0 1
Output
9
Explanation
There are 3 valid subarrays of length 1, 1 of length 2, 3 of length 3, 1 of length 4 and 1 of length 5, totaling 9.