#P7450. [THUSC 2017] 巧克力

    ID: 8325 远端评测题 5000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 DP2017二分Special Judge随机化THUSC

[THUSC 2017] 巧克力

Problem Description

“Life is like a box of chocolates, you never know what the next one tastes like.”

Mingming received a large bar of chocolate. It contains many small pieces arranged in nn rows and mm columns. Each small piece has its own unique pattern: some are starfish, some are shells, some are conchs... and some have been crushed so that their patterns can no longer be recognized. Mingming assigns each piece a deliciousness value ai,ja_{i,j} (0ai,j1060\le a_{i,j}\le 10^6). The larger this value is, the more delicious the piece is.

Just as Mingming swallowed and was about to enjoy it, Zhouzhou appeared magically. Seeing Zhouzhou’s pleading eyes, Mingming decided to pick some pieces to share with Zhouzhou.

Zhouzhou hopes that the selected chocolate pieces are connected (two pieces are connected if and only if they share a common edge), and that these pieces contain at least kk (1k51\le k\le 5) different types. The crushed pieces cannot be selected.

Mingming wants to satisfy Zhouzhou, but he is also a bit “stingy” and wants to keep as much deliciousness as possible for himself. Therefore, he wants the number of selected pieces to be as small as possible. If, under the condition that the number of selected pieces is minimal, the median of the deliciousness values can be as small as possible, that would be even better. (We define the median of nn numbers as the n+12\left\lfloor\frac{n+1}{2}\right\rfloor-th smallest number.)

Can you help Mingming?

Input Format

Each test point contains multiple groups of testdata.

The first line contains a positive integer TT (1T51\le T\le 5), indicating the number of testdata groups.

For each group of testdata:

The first line contains three positive integers nn, mm, and kk.

The next nn lines each contain mm integers, describing the pattern type ci,jc_{i,j} of each piece. If ci,j=1c_{i,j}=-1, this piece has been crushed and cannot be selected.

The next nn lines each contain mm integers, describing the deliciousness value ai,ja_{i,j} of each piece.

Output Format

Output a total of TT lines. Each line contains two integers separated by a space: the minimum number of pieces and the minimum possible median deliciousness value.

If for some testdata group there is no valid selection方案, output two 1-1 on the corresponding line.

1
5 4 5
3 4 3 4
5 5 -1 5
-1 4 5 5
5 5 4 2
1 -1 2 4
1 3 1 1
3 2 3 3
4 4 4 5
8 9 9 5
7 2 6 3
9 5

Hint

Test Point ID Constraints on n,mn,m Constraints on ci,jc_{i,j} Partial Score Rule
1 n=1,1m233n=1,1\le m\le233 ci,j=1c_{i,j}=-1 or 1ci,jn×m1\le c_{i,j}\le n\times m A\text{A}
2 1n×m201\le n\times m\le 20
3~4 n=2,m=15n=2,m=15
5~6 1n×m301\le n\times m\le 30
7~9 1n×m501\le n\times m\le 50 ci,j=1c_{i,j}=-1 or 1ci,j81\le c_{i,j}\le8
10 1n×m2331\le n\times m\le 233
11~12 B\text{B}
13~15 ci,j=1c_{i,j}=-1 or 1ci,j141\le c_{i,j}\le14
16~20 ci,j=1c_{i,j}=-1 or 1ci,jn×m1\le c_{i,j}\le n\times m
21 This test point is not scored.

A\text{A}: If the minimum number of pieces is correct, but the minimum median is wrong, the contestant can get 80%80\% of the score for this test point.
B\text{B}: If the minimum number of pieces is correct, but the minimum median is wrong, the contestant can get 60%60\% of the score for this test point.

Translated by ChatGPT 5