-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommonDays.cpp
More file actions
43 lines (37 loc) · 1.3 KB
/
CommonDays.cpp
File metadata and controls
43 lines (37 loc) · 1.3 KB
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
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; // Number of workers
cin >> n;
vector<int> masks(n); // Vector to store masks for each worker
// Reading input and setting masks
for (int i = 0; i < n; ++i) {
int num_wrkr; // Number of days the worker works
cin >> num_wrkr;
int mask = 0; // Initialize mask to 0
for (int j = 0; j < num_wrkr; ++j) {
int day;
cin >> day;
mask = mask | (1 << day); // Set the bit corresponding to 'day'
}
masks[i] = mask; // Store the mask in the vector
}
int max_days = 0; // Maximum number of common days
int person1 = -1; // Index of first worker
int person2 = -1; // Index of second worker
// Finding the pair of workers with the maximum common days
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
int intersection = masks[i] & masks[j]; // Intersection of masks
int common_days = __builtin_popcount(intersection); // Count of common days
if (common_days > max_days) {
max_days = common_days;
person1 = i;
person2 = j;
}
}
}
// Output the result
cout << person1 << " " << person2 << "\n";
return 0;
}