Created
July 21, 2017 23:10
-
-
Save Resisty/e03ed150127eab2985d82a4f7575a208 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
import sys | |
import collections | |
n,m = input().strip().split(' ') | |
n,m = [int(n),int(m)] | |
topic = [] | |
topic_i = 0 | |
for topic_i in range(n): | |
topic_t = str(input().strip()) | |
topic.append(topic_t) | |
topics = collections.defaultdict(set) | |
pairs = [] | |
for i in range(len(topic)): | |
# Pick an item | |
item, sublist = topic[i], topic[0:i]+topic[i+1:] | |
length = len(sublist) | |
for j in range(length): | |
# Pick another item, thus comparing all combinations | |
other = sublist[j] | |
# Count the number of subjects the combination "knows" | |
topic_bin = int(other, 2) | int(item, 2) | |
topic_int = bin(topic_bin).count('1') | |
# Since we're dealing with two lists, adjust the inner index to be | |
# the index of the same item in the outer index | |
pair = i, j+1 if j >= i and j < length else j | |
# Since indices are exclusive, make sure we're checking combinations and not permutations | |
pair = (pair[0], pair[1]) if pair[0] < pair[1] else (pair[1], pair[0]) | |
# Obtain a hashable format for the indices | |
pair = '%d.%d' % (pair[0], pair[1]), topic_int | |
# Squirrell away the pair and their count of known topics for now | |
pairs.append(pair) | |
for pair in pairs: | |
# Using a set is arguably overkill but if we ever wind up with the same pair this avoids duplicates | |
topics[pair[1]].add(pair[0]) | |
most = max(topics.keys()) | |
pairs = topics[most] | |
print('%d\n%d' % (most, len(pairs))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment