PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000120. Điểm lớn nhất khi chia xâu (Maximum Score After Splitting a String)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Điểm lớn nhất khi chia xâu (Maximum Score After Splitting a String)
Maximum Score After Splitting a String
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
A binary string of length is given. Cut it between two adjacent characters, forming two nonempty contiguous parts. The score is the count of zeros in the left part plus the count of ones in the right part. Determine the greatest achievable score.
Input
The only line contains the string . Let be its length.
Output
Print the maximum score as an integer.
Subtasks
- Subtask 1 (20 points): ; for .
- Subtask 2 (30 points): ; for .
- Subtask 3 (50 points): ; for .
Example 1
Input
011101
Output
5
Explanation
Cuts after 1, 2, 3, 4, 5 characters score 5, 4, 3, 2, 3. The split 0 and 11101 yields 1 + 4 = 5, the maximum.
Example 2
Input
00111
Output
5
Explanation
The parts 00 and 111 score 2 + 3 = 5. No score exceeds the length 5.
Example 3
Input
1111
Output
3
Explanation
There are no zeros. Cutting after the first character leaves three ones on the right.