NiceTable
SRM 717 · 2017-05-20 · by Arterm
Problem Statement
You are given a
We say that a table is nice if there are two sequences x, y of zeroes and ones such that for each valid pair of indices i, j we have t[i][j] = x[i] xor y[j].
Some technical remarks:
- The number of elements in x should be equal to the number of rows of the table, i.e., the number of elements in t.
- The number of elements in y should be equal to the number of columns of the table, i.e., the length of each string in t.
- The operation xor (exclusive or) is defined as follows: 0 xor 0 = 0, 1 xor 1 = 0, 0 xor 1 = 1, and 1 xor 0 = 1.
Verify whether the given table is nice. Return "Nice" if it is nice and "Not nice" otherwise. Note that the return value is case-sensitive.
Constraints
- t will contain between 1 and 5 elements, inclusive.
- Each element of t will contain between 1 and 5 characters, inclusive.
- All elements of t will contain the same number of characters.
- Each element of t will consist only of characters '0' and '1'.
{"01",
"10"}
Returns: "Nice"
One valid choice is to choose x = y = {1, 0}.
{"01",
"11"}
Returns: "Not nice"
Assume that t is nice. The sequences x and y have to satisfy the following constraints: x[0] xor y[0] = 0 x[0] xor y[1] = 1 x[1] xor y[0] = 1 x[1] xor y[1] = 1 From the first constraint we see that x[0] = y[0]. From the second and the third constraint we can then derive that we must also have x[1] = y[1]. But then the fourth constraint is not satisfied, which is a contradiction. Therefore, this t is not nice.
{"010",
"101",
"010"}
Returns: "Nice"
Here one of possible x and y are x = y = "101".
{"01", "01"}
Returns: "Nice"
{"1"}
Returns: "Nice"
{"0100",
"1011",
"0100"}
Returns: "Nice"
Here, one valid choice is x = {1, 0, 1} and y = {1, 0, 1, 1}.
Submissions are judged against all 43 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class NiceTable with a public method string isNice(vector<string> t) · 43 test cases · 2 s / 256 MB per case