PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000068. Chia tiền tố theo tỷ lệ D/K (Diluc and Kaeya)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chia tiền tố theo tỷ lệ D/K (Diluc and Kaeya)
Diluc and Kaeya
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a string s containing only D and K. A nonempty substring has ratio a:b where a and b are its counts of D and K. Ratios a:b and c:d are equal if ad=bc. For each prefix of s, compute the maximum number of nonempty contiguous blocks into which that entire prefix can be partitioned such that all blocks have the same ratio.
Input
An integer n followed by a string s of length n.
Output
n space-separated integers, one answer per prefix.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
4
DKDK
Output
1 1 1 2
Explanation
DKDK can be split into DK and DK, each having D:K ratio 1:1. Earlier prefixes cannot be split into more than one valid block.