PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000183. Dãy ký tự X liên tiếp dài nhất (Longest X)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Dãy ký tự X liên tiếp dài nhất (Longest X)
Longest X
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A string consists of X and .. One operation changes a dot into X. You may perform any number of operations from zero to . Find the greatest possible length of a consecutive run of X after the changes, or zero if no X can be obtained.
Input
The first line contains . The second contains integer .
Output
Print the maximum possible length.
Subtasks
- Subtask 1 (20 points): ; ; the string contains only
Xand.. - Subtask 2 (30 points): ; ; the string contains only
Xand.; . - Subtask 3 (50 points): ; ; the string contains only
Xand..
Example 1
Input
XX...X.X.X.
2
Output
5
Explanation
Change the dots at positions 7 and 9 (1-based), obtaining a run from 6 through 10. Each length-six window contains at least three dots.
Example 2
Input
XXXX
200000
Output
4
Explanation
All four characters are already X; no change is needed.