시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
5 초 | 128 MB | 0 | 0 | 0 | 0.000% |
In the not-so-distance future, space engineers can invent a new technology for traveling through space and name it as “warp-drive”. This warp-drive can make a spaceship travel faster than light speed. It works by bending an amount of distance in space and make a ship travel through that bended space in a single “hop”. To travel through space, a spaceship (that is equipped with this warp-drive) may have to perform more than one hop between the beginning and the ending points. The amount of energy/power to hop depends on the current state/configuration of the warp-drive. And some amount of energy is also consumed in order to prepare or switch to any warp-drive state.
Suppose that you are an engineer on a battle spaceship. Your duty is to control/configure the warp-drive so that it will consume as less energy as possible for any traveling. For each traveling, you will be provided with a sequence of hops, which you have to find a corresponding sequence of warp-drive configurations that use the lowest energy.
In order to accomplish your duty, you have to build a computer program to find the lowest energy of warp-drive configuration sequence for any given hop sequence based on two tables of warp-driver energy consumptions. The first table shows the energy for switching between any two states. The second table shows the energy consumption related to warp-drive states and hops.
Input is a standard input which consists of 4 parts, separated by a blank line.
The first part defines the sizes of warp-drive states and hop types.
The second part is a table showing the energy for switching warp-drive states. The table size is N rows and N columns, which contains N2 energy values.
The third part is a table showing the energy consumption in performing hops for each state drive.
The table size is N rows and H columns, which contains N by H values.
The fourth part is a set of hop sequences. The number of sequences in this set is between 1 and 1,000.
The blank line after the fourth part is the termination of the input.
For each hop sequence in the fourth part of the input, write 2 parts of output as follows
4 5 1 2 6 1 3 4 3 17 2 3 9 3 1 21 1 8 0 0 0 0 0 3 3 2 4 3 2 2 4 3 1 4 2 2 7 7 0 4 1 2 3 2
9 3 2 23 1 1 2 3
There are 15 lines in the sample input and 4 lines in the sample output.
In the first sample output (solution for input line #13), the minimum total energy is 9. The warpdrive state sequence is [3 2] or [0- 3 2 -0]. There are 3 state switchings from 0 → 3, 3 → 2, and 2 → 0, which consumes 1 + 1 + 2 = 4. And two hops (0 and 4) at state 3 and 2 respectively, which consumes 4 +1 = 5. So the total energy is 4 + 5 = 9.
In the last sample output, the minimum energy is 23. The solution is [0- 1 1 2 3 -0] which draws 23 energy in total.