PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000194. Đếm cách chia dãy thành ba đoạn (Ways to Split Array Into Three Subarrays)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm cách chia dãy thành ba đoạn (Ways to Split Array Into Three Subarrays)
Ways to Split Array Into Three Subarrays
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given nonnegative integers, choose two cuts partitioning the entire array into three nonempty consecutive intervals , , . A split is valid if the first interval sum is at most the second, and the second is at most the third. Count valid cut pairs modulo .
Input
The first line contains . The second contains integers .
Output
Print the number of valid splits modulo .
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; ; for all .
- Subtask 3 (50 points): ; .
Example 1
Input
3
1 1 1
Output
1
Explanation
The only cut pair is , with all sums equal to 1.
Example 2
Input
6
1 2 2 2 5 0
Output
3
Explanation
The valid cut pairs are , , with sums , , .
Example 3
Input
3
3 2 1
Output
0
Explanation
The only split has sums 3,2,1, which are not ordered.
Example 4
Input
4
0 0 0 0
Output
3
Explanation
All three cut pairs have three zero sums.