-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeam_Name.cpp
More file actions
46 lines (44 loc) · 927 Bytes
/
Team_Name.cpp
File metadata and controls
46 lines (44 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* @Date : 2021-02-07 00:17:56
* @Author : aerma7309
*/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
int FastIO = []() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
return 0;
}();
void solve()
{
int n;
cin >> n;
map<string, set<char>> m;
string s;
for (int i = 0; i < n; i++)
cin >> s, m[s.substr(1)].insert(s[0]);
int ans = 0;
for (auto &i : m)
{
for (auto &j : m)
{
if (i != j)
{
vector<char> v;
set_union(i.second.begin(), i.second.end(), j.second.begin(), j.second.end(), back_inserter(v));
ans += (v.size() - i.second.size()) * (v.size() - j.second.size());
}
}
}
cout << ans << '\n';
}
signed main()
{
int t;
cin >> t;
while (t--)
solve();
return 0;
}