-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path银联-04.cpp
71 lines (66 loc) · 2.5 KB
/
银联-04.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class Solution
{
public:
int coopDevelop(vector<vector<int>> &skills)
{
int n = skills.size();
for (vector<int> &skill : skills)
sort(skill.begin(), skill.end(), less<int>());
sort(skills.begin(), skills.end(),
[](const vector<int> &a, const vector<int> &b) { return a.size() < b.size(); });
unordered_map<string, int64_t> m;
int64_t tot = (int64_t)n * ((int64_t)n - 1) / 2, mod = 1e9 + 7;
for (vector<int> &skill : skills)
{
if (skill.size() == 1)
{
string str1 = to_string(skill[0]);
tot -= m[str1];
m[str1]++;
}
else if (skill.size() == 2)
{
string str1 = to_string(skill[0]), str2 = to_string(skill[1]);
tot -= m[str1];
tot -= m[str2];
tot -= m[str1 + "&" + str2];
m[str1 + "&" + str2]++;
}
else if (skill.size() == 3)
{
string str1 = to_string(skill[0]), str2 = to_string(skill[1]), str3 = to_string(skill[2]);
tot -= m[str1];
tot -= m[str2];
tot -= m[str3];
tot -= m[str1 + "&" + str2];
tot -= m[str1 + "&" + str3];
tot -= m[str2 + "&" + str3];
tot -= m[str1 + "&" + str2 + "&" + str3];
m[str1 + "&" + str2 + "&" + str3]++;
}
else if (skill.size() == 4)
{
string str1 = to_string(skill[0]), str2 = to_string(skill[1]), str3 = to_string(skill[2]),
str4 = to_string(skill[3]);
tot -= m[str1];
tot -= m[str2];
tot -= m[str3];
tot -= m[str4];
tot -= m[str1 + "&" + str2];
tot -= m[str1 + "&" + str3];
tot -= m[str1 + "&" + str4];
tot -= m[str2 + "&" + str3];
tot -= m[str2 + "&" + str4];
tot -= m[str3 + "&" + str4];
tot -= m[str1 + "&" + str2 + "&" + str3];
tot -= m[str1 + "&" + str2 + "&" + str4];
tot -= m[str1 + "&" + str3 + "&" + str4];
tot -= m[str2 + "&" + str3 + "&" + str4];
tot -= m[str1 + "&" + str2 + "&" + str3 + "&" + str4];
m[str1 + "&" + str2 + "&" + str3 + "&" + str4]++;
};
};
tot %= mod;
return tot;
}
};