CF744E.Hongcow Masters the Cyclic Shift

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Hongcow's teacher heard that Hongcow had learned about the cyclic shift, and decided to set the following problem for him.

You are given a list of nn strings s1,s2,...,sns_{1},s_{2},...,s_{n} contained in the list AA .

A list XX of strings is called stable if the following condition holds.

First, a message is defined as a concatenation of some elements of the list XX . You can use an arbitrary element as many times as you want, and you may concatenate these elements in any arbitrary order. Let SXS_{X} denote the set of of all messages you can construct from the list. Of course, this set has infinite size if your list is nonempty.

Call a single message good if the following conditions hold:

  • Suppose the message is the concatenation of kk strings w1,w2,...,wkw_{1},w_{2},...,w_{k} , where each wiw_{i} is an element of XX .
  • Consider the w1+w2+...+wk|w_{1}|+|w_{2}|+...+|w_{k}| cyclic shifts of the string. Let mm be the number of these cyclic shifts of the string that are elements of SXS_{X} .
  • A message is good if and only if mm is exactly equal to kk .

The list XX is called stable if and only if every element of SXS_{X} is good.

Let f(L)f(L) be 11 if LL is a stable list, and 00 otherwise.

Find the sum of f(L)f(L) where LL is a nonempty contiguous sublist of AA (there are contiguous sublists in total).

输入格式

The first line of input will contain a single integer nn ( 1<=n<=301<=n<=30 ), denoting the number of strings in the list.

The next nn lines will each contain a string sis_{i} ().

输出格式

Print a single integer, the number of nonempty contiguous sublists that are stable.

输入输出样例

  • 输入#1

    4
    a
    ab
    b
    bba
    

    输出#1

    7
    
  • 输入#2

    5
    hh
    ee
    ll
    ll
    oo
    

    输出#2

    0
    
  • 输入#3

    6
    aab
    ab
    bba
    b
    ab
    c
    

    输出#3

    13
    

说明/提示

For the first sample, there are 1010 sublists to consider. Sublists ["a", "ab", "b"], ["ab", "b", "bba"], and ["a", "ab", "b", "bba"] are not stable. The other seven sublists are stable.

For example, XX = ["a", "ab", "b"] is not stable, since the message "ab" + "ab" = "abab" has four cyclic shifts ["abab", "baba", "abab", "baba"], which are all elements of SXS_{X} .

首页