Skip to content

Commit 875e616

Browse files
authored
Create 2019-F-B.cpp
1 parent d06c71f commit 875e616

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

Diff for: kick-start/2019-F-B.cpp

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
const int MAXN = 2e5+10;
5+
typedef long long LL;
6+
void solve(){
7+
int N,S;
8+
cin >> N >> S;
9+
10+
vector<int> skill[S];
11+
vector<int> ee[N];
12+
for(int i=0 ; i<N ; ++i){
13+
int c;
14+
cin >>c;
15+
for(int _=0 ; _ < c; ++_){
16+
int x;
17+
cin >>x;x--;
18+
ee[i].push_back(x);
19+
skill[x].push_back(i);
20+
}
21+
}
22+
LL ans =0;
23+
map<vector<int>,int> cnt;
24+
for(int i=0 ; i<N ; ++i){
25+
sort(ee[i].begin(),ee[i].end(),[&](const int a,const int b){return skill[a].size() < skill[b].size();});
26+
cnt[ee[i]]++;
27+
}
28+
for(const auto &e : cnt){
29+
vector<int> out = skill[e.first[0]];
30+
// assert deep copy
31+
for(int j=1 ; j<e.first.size() ; ++j){
32+
auto sk = e.first[j];
33+
auto it = set_intersection(skill[sk].begin(),skill[sk].end(),
34+
out.begin(),out.end(),out.begin()
35+
);
36+
out.resize(it - out.begin());
37+
}
38+
ans += (LL)(N - out.size()) * e.second;
39+
}
40+
cout << ans << "\n";
41+
}
42+
43+
44+
45+
46+
int main(){
47+
ios :: sync_with_stdio(0);
48+
cin.tie(0);
49+
// cout.tie(0);
50+
std::cout.precision(10);
51+
std::cout.setf( std::ios::fixed, std:: ios::floatfield );
52+
53+
int T;
54+
cin >> T;
55+
for(int tt =1 ; tt <=T ; ++tt)
56+
{
57+
cout << "Case #" << tt << ": ";
58+
solve();
59+
}
60+
61+
62+
return 0;
63+
}

0 commit comments

Comments
 (0)