-
Notifications
You must be signed in to change notification settings - Fork 111
/
solution.py
32 lines (25 loc) · 1.09 KB
/
solution.py
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
import sys
#Driver code
if __name__ == '__main__':
#input n = attendees, m = topics and known/unknown topics string
N, M = list(map(int, sys.stdin.readline().split()))
T = [int(sys.stdin.readline(), 2) for _ in range(N)]
max_topics, num_teams = 0, 0
# all possible teams of 2 participants
# 0 means participant not know the topic and 1 means know the topic
# in pairing of team if atleast anyone know the topic, then team also know the topic
for i in range(len(T) - 1):
for j in range(i + 1, len(T)):
# OR operation between two participants
# count if it is 1 i.e team know the topic
topics = bin(T[i] | T[j]).count('1')
# count number of teams whoever also know the maximum topics
if(topics == max_topics):
num_teams += 1
# update maximimum number of topics known by a team
if(topics > max_topics):
max_topics = topics
num_teams = 1
# display result
print(max_topics)
print(num_teams)