Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Best Compromise – Kattis, Kattis https://open.kattis.

com/problems/compromise

 Due to a performance problem scoring is currently being


updated slowly. We are working on it!

Best Compromise
There is a saying “a good compromise makes
no one happy”. As distressing as that may be,
I guess most people still think it is a good
idea to seek the best agreement. The problem
though, is to de�ne the measure in which the
word “best” gets a meaning. Let us consider
n people, each with a �rm belief on m
di�erent yes/no issues. We may think of the
Photo by Andy Nelson
people’s beliefs as binary strings b i of length
m for 0 < i ≤ n, i.e. one string per person, with entries re�ecting a
person’s belief in each of the m issues. An agreement is also a binary string a
of length m, indicating the agreed outcome of each of the m issues. Some
would argue that the agreement a that minimises the maximum of
H(b i − a) over all i, where H(x) is the Hamming function counting the
number of non-zero entries of the vector x, is the best compromise.
Unfortunately, it is widely believed that �nding this agreement is
computationally infeasible for n and m large. Another reasonable
suggestion is the agreement that minimises for
1/p
a (∑ ni=1 H(b i − a) p )
some positive integer p. Note in particular that when p → ∞, this measure
coincides with the former. I for one am most content with the choice of
p = 1 though, don’t you agree?

Input

On the �rst line of input is a single positive integer t, telling the number of
test scenarios to follow. Each test scenario is described by two positive
integers n ≤ 100 and m ≤ 100, on a line of their own. Then follow n lines,
each containing a binary string b i on m ‘0’ and ‘1’ characters.

Output

For each test scenario, output the assignment a that minimises the measure

1 of 3 31/03/2023, 06:07
Best Compromise – Kattis, Kattis https://open.kattis.com/problems/compromise
above with p = 1, on a row of its own. If there are several solutions, output
anyone.

Sample Input 1 Sample Output 1

2 00101
5 5 0110010
00000
00100
01001
01101
00101
1 7
0110010

2 of 3 31/03/2023, 06:07
Best Compromise – Kattis, Kattis https://open.kattis.com/problems/compromise

CPU Time limit 1 second

Memory limit 1024 MB

Erfiðleiki 2.1 Easy

Author Andreas Björklund

Feng ið frá Nada Open 2005

Leyfi

3 of 3 31/03/2023, 06:07

You might also like