#P13382. [GCJ 2011 Finals] Runs

[GCJ 2011 Finals] Runs

题目描述

I have a string SS consisting of lower-case alphabetic characters, 'a' - 'z'. Each maximal sequence of contiguous characters that are the same is called a "run". For example, "bookkeeper" has 7 runs. How many different permutations of SS have exactly the same number of runs as SS?

Two permutations aa and bb are considered different if there exists some index ii at which they have a different character: a[i]b[i]a[i] \neq b[i].

输入格式

The first line of the input gives the number of test cases, TT. TT lines follow. Each contains a single non-empty string of lower-case alphabetic characters, SS, the string of interest.

输出格式

For each test case, output one line containing "Case #xx: yy", where xx is the case number (starting from 1) and yy is the number of different permutations of SS that have exactly the same number of runs as SS, modulo 10000031000003.

2
aabcd
bookkeeper
Case #1: 24
Case #2: 7200

提示

Limits

  • 1T1001 \leq T \leq 100.
  • SS is at least 11 character long.

Small dataset (Test set 1 - Visible)

  • SS is at most 100100 characters long.
  • Time limit: 30 3 seconds.

Large dataset (Test set 2 - Hidden)

  • SS is at most 450000450000 characters long.
  • SS has at most 100100 runs.
  • The input file will not exceed 11 megabyte in size.
  • Time limit: 60 6 seconds.