CF922D.Robot Vacuum Cleaner

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Pushok the dog has been chasing Imp for a few hours already.

Fortunately, Imp knows that Pushok is afraid of a robot vacuum cleaner.

While moving, the robot generates a string t consisting of letters 's' and 'h', that produces a lot of noise. We define noise of string t as the number of occurrences of string "sh" as a subsequence in it, in other words, the number of such pairs (i, j), that i < j and and .

The robot is off at the moment. Imp knows that it has a sequence of strings t__i in its memory, and he can arbitrary change their order. When the robot is started, it generates the string t as a concatenation of these strings in the given order. The noise of the resulting string equals the noise of this concatenation.

Help Imp to find the maximum noise he can achieve by changing the order of the strings.

狗狗普绍克已经追击小妖精伊姆普好几个小时了。

幸运的是,伊姆普知道普绍克害怕扫地机器人。

机器人在移动过程中会生成一个仅由字符 's' 和 'h' 组成的字符串 tt,该字符串会产生大量噪音。我们定义字符串 tt 的噪音为其中子序列 "sh" 出现的次数,即满足 i<ji < j、ti=’s’t_i = \text{'s'} 且 tj=’h’t_j = \text{'h'} 的下标对 (i, j)(i,\,j) 的个数。

目前机器人处于关闭状态。伊姆普知道其内存中存有一组字符串 tit_i,他可以任意调整这些字符串的顺序。当机器人启动后,它将按给定顺序拼接这些字符串,生成最终的字符串 tt;该字符串的噪音即为该拼接结果的噪音。

请帮助伊姆普找出:通过重新排列这些字符串,所能达到的最大噪音值。

输入格式

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of strings in robot's memory.

Next n lines contain the strings _t_1, _t_2, ..., t__n, one per line. It is guaranteed that the strings are non-empty, contain only English letters 's' and 'h' and their total length does not exceed 105.

第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)——表示机器人内存中字符串的数量。

接下来的 nn 行每行包含一个字符串 t1,t2,…,tnt_1, t_2, \dots, t_n。保证这些字符串非空,仅由英文字母 's' 和 'h' 组成,且所有字符串的总长度不超过 10510^5。

输出格式

Print a single integer — the maxumum possible noise Imp can achieve by changing the order of the strings.

输出一个整数——Imp 通过改变字符串的顺序所能达到的最大噪声值。

输入输出样例

  • 输入#1

    4
    ssh
    hs
    s
    hhhs

    输出#1

    18
  • 输入#2

    2
    h
    s

    输出#2

    1

说明/提示

The optimal concatenation in the first sample is ssshhshhhs.

第一个样例中的最优拼接结果为 ssshhshhhs。

输入解题思路,AI测评打分。不知道怎么写?

首页