#P15821. [JOI Open 2013] Vote-Value Disparity

    ID: 15759 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>2013提交答案Special JudgeJOI(日本)

[JOI Open 2013] Vote-Value Disparity

Description

This is an Output-only task.

A national election will be held in the JOI kingdom. The JOI kingdom consists of NN provinces.

The map of the JOI kingdom is a rectangular-shaped grid consisting of H×WH \times W blocks. There are HH blocks in the vertical direction, and there are WW blocks in the horizontal direction. A block is connected with another block by one of the four sides (left, right, top, bottom) of it. The H×WH \times W blocks are divided into NN provinces. Each province is a connected region consisting of blocks. In total, there are PiP_i voters in the ii-th province (1iN1 \le i \le N).

You are the chairman of the National Election Committee of JOI. Your task is to divide the NN provinces into KK electoral districts (1KN1 \le K \le N) in order to elect KK representatives. Each electoral district should contain at least one province, and the blocks belonging to an electoral district should form a connected region. Note that a block is connected with another block by one of the four sides (left, right, top, bottom). Two blocks sharing only a vertex are not connected.

For each electoral district, the ratio 1/1 / (the number of voters in the electoral district) is called the weight of a single vote of the electoral district. The vote-value disparity is defined to be the maximal weight of a single vote for all electoral districts divided by the the minimal weight of a single vote for all electoral districts.

Recently, the value of "the vote-value disparity" becomes a serious social issue. You have to make this value as small as possible.

Task

Given the information of the provinces of the JOI kingdom and the number of representatives, determine how to divide the provinces into electoral districts so that the value of the vote-value disparity is as small as possible.

Input Format

Read the following data from the standard input.

  • The first line of input contains four space separated integers H,W,N,KH, W, N, K, where the height of the map of the JOI kingdom is HH, the width is WW, the number of provinces is NN, the number of representatives is KK.
  • Each of the following HH lines contains WW space separated integers. In the ii-th line (1iH1 \le i \le H), the jj-th integer (1jW1 \le j \le W) is SijS_{ij} (1SijN1 \le S_{ij} \le N). This means the block in ii-th row from above and the jj-th column from left belongs to the SijS_{ij}-th province.
  • In the ii-th line (1iN1 \le i \le N) of the following NN lines contains an integer PiP_i, the number of voters in the ii-th province.

Output Format

Write the way to divide the provinces into electoral districts in NN lines. The ii-th line (1iN1 \le i \le N) of output should contain an integer, the number of the electoral district where the ii-th province belongs.

2 3 4 3
1 1 1
2 3 4
3
5
7
10
1
2
1
3

Hint

Sample 1 Explanation

In this example, the shape of the JOI kingdom is as follows.

:::align{center} :::

The number of voters in each province is 3, 5, 7, 10, respectively. In this sample output, the provinces are divided into electoral districts as follows.

  • Electoral District 1: Province 1 and Province 3
  • Electoral District 2: Province 2
  • Electoral District 3: Province 4

The number of voters in each electoral district is 10, 5, 10, respectively. The weight of a single vote for each electoral district is 0.1, 0.2, 0.1, respectively. Therefore, the vote-value disparity is 0.2/0.1=20.2 / 0.1 = 2. If X=1.5X = 1.5, Y=3Y = 3, we have $\left(\frac{3 - 2}{3 - 1.5}\right)^2 \times 20 = 8.8\cdots$ and this output is worth 8 points.

In this sample input, the following division is not allowed because the Electoral District 2 does not form a connected region.

  • Electoral District 1: Province 1
  • Electoral District 2: Province 2 and Province 4
  • Electoral District 3: Province 3

Constraints

All input data satisfy the following conditions.

  • 1H2001 \le H \le 200
  • 1W2001 \le W \le 200
  • 1N100001 \le N \le 10000
  • 1KN1 \le K \le N
  • 1Pi1000001 \le P_i \le 100000 (1iN1 \le i \le N)
  • For each province, the blocks belonging to the province form a connected region.

Grading

For each input, your score is calculated as follows.

If your output does not satisfy the condition in the task statement, your score is 0. If it satisfies the condition, let DD denote the vote-value disparity of your output. Then your score is calculated by the following way.

  • If Y<DY < D, your score is 0.
  • If X<DYX < D \le Y, your score is the value of (YDYX)2×20\left(\frac{Y - D}{Y - X}\right)^2 \times 20 truncated to zero decimal places.
  • If DXD \le X, your score is 20.

The values of X,YX, Y are given in the following table.

Input X Y
01.txt 1.02 2
02.txt 1.66 2.5
03.txt 1.06
04.txt 1.005 3
05.txt 1.0005 2