#GD0000081. Tô màu bằng những lần xuất hiện (Color with Occurrences)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tô màu bằng những lần xuất hiện (Color with Occurrences)
Color with Occurrences
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given a target string and lowercase patterns , one operation selects any contiguous occurrence of one pattern in and colors all its positions. Positions may be colored more than once. Color the whole target with the minimum number of operations, reporting pattern indices and one-based starting positions, or -1 if impossible. Any minimum-length plan is valid.
Input
The first line contains . The second line contains . The following lines contain .
Output
Print -1 if impossible. Otherwise print minimum operation count , then lines each containing pattern index and one-based occurrence start .
Subtasks
- Subtask 1 (20 points): ; ; ; all characters are lowercase letters
a–z. - Subtask 2 (30 points): ; ; ; all characters are lowercase letters
a–z. - Subtask 3 (50 points): ; ; ; all characters are lowercase letters
a–z.
Examples
Input
bababa
2
ba
aba
Output
3
1 1
1 3
1 5
Explanation
Use pattern (ba) at starting positions , , and to color positions –, –, and – respectively. Covering the first position requires the occurrence starting at , while one further operation cannot cover all of positions –. Thus three is minimum.