#GL0000258. Bảng phân ca (Shift Table)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bảng phân ca (Shift Table)
Shift Table
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Takahashi and Aoki will work part-time for the next days. Takahashi's schedule is represented by a string of length . On day , the character is # if Takahashi works and . if he is absent.
Aoki constructs his own schedule as follows:
- Choose a positive divisor of with .
- Independently decide Aoki's attendance on the first days.
- For in increasing order, set the attendance on day to be the same as on day .
Consequently, Aoki's schedule is periodic with period . Different choices of can produce the same final schedule. Count each distinct schedule only once.
Determine the number of distinct schedules Aoki can create such that on every day from to , at least one of the two people works. Print the number modulo .
Input
- The first line contains an integer , the number of days.
- The second line contains a string of exactly characters from {
#,.}, describing Takahashi's attendance on days through , in order.
Output
Print one integer: the number of distinct valid schedules for Aoki, modulo .
Subtasks
- Subtask 1 (20 points): ; ; every character of is
#or.. - Subtask 2 (30 points): ; ; every character of is
#or.. - Subtask 3 (50 points): ; ; every character of is
#or..
Examples
Example 1
Input
6
##.#.#
Output
3
Explanation
Takahashi works on days and is absent on days , so Aoki must work on days and . The permitted divisors of are . Period permits ######. Period also permits #.#.#.. Period also permits .##.##. After removing duplicates, there are exactly three schedules: ######, #.#.#., and .##.##.
Example 2
Input
7
...####
Output
1
Explanation
Since is prime, the only permitted divisor is . Aoki's attendance must be identical on all days. Because Takahashi is absent on the first three days, Aoki must work on every day, giving the sole schedule #######.
Example 3
Input
12
####.####.##
Output
19
Explanation
Takahashi is absent on days and , requiring Aoki to work on both. The permitted periods are . Count schedules with each period, then subtract schedules already counted using a smaller divisor. The counts of newly introduced schedules for are respectively . Their sum is .