Special Subarrays
Practice
2.5 (6 votes)
Data structures
Advanced data structures
Trie
Problem
23% Success 899 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code
An array is said to be special, if we can break it down into subarrays where every subarray (length > 1) starts and ends with \(0\) and rest all other numbers are \(1\).
Given \(N\) binary arrays.
Sam decided to write down all the distinct prefix subarrays of the given \(N\) binary arrays on a paper (he'll write distinct prefix only). After that he counts the number of special subarrays in every prefix and sum that up (a special subarray will be counted as many times as it is contained in each prefix).
Find the sum found by Sam modulo \(10^9 + 7\).
Input Format:
- The first line contains \(N\) denoting the number of binary arrays.
- The \(i^{th}\) of the next \(N\) lines contains the binary array in form of a string \(S[i]\).
Output Format:
Sum found by Sam modulo \(10^9 + 7\)
Constraints:
\(1 \le N \le 10^3 \\ 1 \le S[i] \le 10^5 \\ 1 \le \sum_{i = 1}^{N}S[i] \le 2 \times 10^6 \)
Submissions
Please login to view your submissions
Similar Problems
Points:50
Tags:
Depth First SearchTrieData StructuresDynamic ProgrammingAdvanced Data Structures
Points:50
3 votes
Tags:
TrieAdvanced Data StructuresC++Data Structures
Points:50
3 votes
Tags:
TrieAdvanced Data StructuresData Structures
Editorial