#P8899. [USACO22DEC] Reverse Engineering B

[USACO22DEC] Reverse Engineering B

Description

Elsie has a program that takes as input an array of NN variables (1N1001 \le N \le 100), b[0],,b[N1]b[0], \cdots, b[N-1], where each variable equals 00 or 11, and returns the result of applying a sequence of if / else if / else statements to the input. Each branch checks at most one input variable and returns 00 or 11. An example of such a program is:

if (b[1] == 1) return 1;
else if (b[0] == 0) return 0;
else return 1;

For example, if the input to the program above is "10" (i.e., b[0]=1b[0] = 1 and b[1]=0b[1] = 0), then the output should be 11.

Elsie told Bessie the correct outputs for MM different inputs (1M1001 \le M \le 100). Bessie is now trying to reverse engineer Elsie’s program. Unfortunately, Elsie may have lied; there might be no program of the above form whose behavior matches everything Elsie said.

For each of TT test cases (1T101 \le T \le 10), determine whether Elsie is certainly lying.

Input Format

The first line contains TT, the number of test cases.

For each test case, the first line contains two integers NN and MM. Each of the following MM lines contains a string of NN characters, each 00 or 11, representing an input (the values of b[0]b[N1]b[0] \cdots b[N-1]), followed by another character (00 or 11) representing the output. Consecutive test cases are separated by a blank line.

Output Format

For each test case, output a single line containing OK\texttt{OK} or LIE\texttt{LIE}, indicating respectively that Elsie might not be lying or is certainly lying.

4

1 3
0 0
0 0
1 1

2 4
00 0
01 1
10 1
11 1

1 2
0 1
0 0

2 4
00 0
01 1
10 1
11 0
OK
OK
LIE
LIE

Hint

Explanation for Sample 1

Here is one valid program for the first test case:

if (b[0] == 0) return 0;
else return 1;

Here is another valid program for the first test case:

if (b[0] == 1) return 1;
else return 0;

Here is one valid program for the second test case:

if (b[1] == 1) return 1;
else if (b[0] == 0) return 0;
else return 1;

Clearly, no valid program exists for the third test case, since Elsie’s program must always produce the same output for the same input.

It can be proven that no valid program exists for the last test case.

Properties of test points

  • Test points 2233 satisfy N=2N = 2.
  • Test points 4455 satisfy M=2M = 2.
  • Test points 661212 have no additional constraints.

Translated by ChatGPT 5