CF1070J.Streets and Avenues in Berhattan

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Berhattan is the capital of Berland. There are nn streets running parallel in the east-west direction (horizontally), and there are mm avenues running parallel in the south-north direction (vertically). Each street intersects with each avenue, forming a crossroad. So in total there are n⋅mn \cdot m crossroads in Berhattan.

Recently, the government has changed in Berland. The new government wants to name all avenues and all streets after heroes of revolution.

The special committee prepared the list of kk names. Only these names can be used as new names for streets and avenues. Each name can be used at most once.

The members of committee want to name streets and avenues in the way that minimizes inconvenience for residents. They believe that if street and avenue names start with the same letter, then their crossroad will be inconvenient. Hence only the first letter of each name matters.

Given first letters of kk names, find CC — minimal possible number of inconvenient crossroads in Berhattan after the naming process.

贝哈顿(Berhattan)是贝尔兰(Berland)的首都。有 nn 条街道沿东西方向(水平方向)平行延伸,有 mm 条大道沿南北方向(垂直方向)平行延伸。每条街道与每条大道均相交,形成一个路口。因此,贝哈顿总共有 n⋅mn \cdot m 个路口。

最近,贝尔兰政府发生了更迭。新政府希望以革命英雄的名字来命名所有大道和所有街道。

一个特别委员会准备了一份包含 kk 个名字的名单。仅能从这份名单中选取名字为街道和大道重新命名,且每个名字至多使用一次。

委员会成员认为,若某条街道与某条大道的名字首字母相同,则其交汇形成的路口将给居民带来不便。因此,仅有每个名字的首字母是重要的。

已知这 kk 个名字的首字母,求在完成命名后,贝哈顿中不便路口数的最小可能值 CC。

输入格式

Input contains one or several test cases to process. The first line contains tt (1≤t≤300001 \le t \le 30000) — the number of test cases. Solve test cases separately, test cases are completely independent and do not affect each other.

The description of tt test cases follows. Each test case starts with line with space-separated numbers n,m,kn, m, k (1≤n,m≤300001 \le n,m \le 30000; n+m≤k≤2⋅105n+m \le k \le 2\cdot10^5) — the number of streets, number of avenues and the number of names in the committee's list, respectively.

The the second line of each test case contains a string of kk uppercase English letters. ii-th letter of the string is the first letter of ii-th name from the committee's list.

It's guaranteed that the sum of numbers nn from all test cases is not greater than 3000030000. Similarly, the sum of numbers mm from all test cases is not greater than 3000030000. The sum of numbers kk from all test cases is not greater than 2⋅1052\cdot10^5.

输入包含一个或多个待处理的测试用例。第一行包含 tt(1≤t≤300001 \le t \le 30000)—— 测试用例的数量。请分别求解各测试用例,各测试用例完全独立,互不影响。

接下来是 tt 个测试用例的描述。每个测试用例以一行开始,该行包含三个以空格分隔的整数 n,m,kn, m, k(1≤n,m≤300001 \le n,m \le 30000;n+m≤k≤2⋅105n+m \le k \le 2\cdot10^5),分别表示街道数量、大道数量以及委员会名单中姓名的数量。

每个测试用例的第二行包含一个长度为 kk 的字符串,由大写英文字母组成。该字符串中第 ii 个字母即为委员会名单中第 ii 个姓名的首字母。

保证所有测试用例中 nn 的总和不超过 3000030000;同理,所有测试用例中 mm 的总和不超过 3000030000;所有测试用例中 kk 的总和不超过 2⋅1052\cdot10^5。

输出格式

For each test case print single number CC in the separate line — minimal possible number of inconvenient crossroads in Berhattan after the naming process.

对于每个测试用例,在单独一行中输出一个整数 CC —— 命名过程结束后,Berhattan 中不便路口的最小可能数量。

输入输出样例

  • 输入#1

    2
    2 3 9
    EEZZEEZZZ
    2 7 9
    EEZZEEZZZ

    输出#1

    0
    4
  • 输入#2

    2
    4 4 8
    CZBBCZBC
    1 1 4
    TTCT

    输出#2

    1
    0

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

首页