CF2111B.Fibonacci Cubes

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Fibonacci Cubes

There are nn Fibonacci cubes, where the side of the ii-th cube is equal to fif_{i}, where fif_{i} is the ii-th Fibonacci number.

In this problem, the Fibonacci numbers are defined as follows:

  • f1=1f_{1} = 1
  • f2=2f_{2} = 2
  • fi=fi1+fi2f_{i} = f_{i - 1} + f_{i - 2} for i>2i \gt 2

There are also mm empty boxes, where the ii-th box has a width of wiw_{i}, a length of lil_{i}, and a height of hih_{i}.

For each of the mm boxes, you need to determine whether all the cubes can fit inside that box. The cubes must be placed in the box following these rules:

  • The cubes can only be stacked in the box such that the sides of the cubes are parallel to the sides of the box;
  • Every cube must be placed either on the bottom of the box or on top of other cubes in such a way that all space below the cube is occupied;
  • A larger cube cannot be placed on top of a smaller cube.

Input

Each test consists of several test cases. The first line contains a single integer tt (1t1031 \le t \le 10^{3}) — the number of test cases. The description of the test cases follows.

In the first line of each test case, there are two integers nn and mm (2n10,1m21052 \le n \le 10, 1 \le m \le 2 \cdot 10^{5}) — the number of cubes and the number of empty boxes.

The next mm lines of each test case contain 33 integers wiw_{i}, lil_{i}, and hih_{i} (1wi,li,hi1501 \le w_{i}, l_{i}, h_{i} \le 150) — the dimensions of the ii-th box.

Additional constraints on the input:

  • The sum of mm across all test cases does not exceed 21052 \cdot 10^{5}.

Output

For each test case, output a string of length mm, where the ii-th character is equal to "1" if all nn cubes can fit into the ii-th box; otherwise, the ii-th character is equal to "0".

Note

In the first test case, only one box is suitable. The cubes can be placed in it as follows:

Samples

2
5 4
3 1 2
10 10 10
9 8 13
14 7 20
2 6
3 3 3
1 2 1
2 1 2
3 2 2
2 3 1
3 2 4
0010
100101

在线编程 IDE

建议全屏模式获得最佳体验