CF1218C.Jumping Transformers

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You, the mighty Blackout, are standing in the upper-left (0,0)(0,0) corner of NN x MM matrix. You must move either right or down each second.

There are KK transformers jumping around the matrix in the following way. Each transformer starts jumping from position (x,y)(x,y) , at time tt , and jumps to the next position each second. The xx -axes grows downwards, and yy -axes grows to the right. The order of jumping positions is defined as (x,y),(x+d,yd),(x+d,y),(x,y+d){(x,y),(x+d,y-d),(x+d,y),(x,y+d)} , and is periodic. Before time tt transformer is not in the matrix.

You want to arrive to the bottom-right corner (N1,M1)(N-1,M-1) , while slaying transformers and losing the least possible amount of energy. When you meet the transformer (or more of them) in the matrix field, you must kill them all, and you lose the sum of the energy amounts required to kill each transformer.

After the transformer is killed, he of course stops jumping, falls into the abyss and leaves the matrix world. Output minimum possible amount of energy wasted.

输入格式

In the first line, integers NN , MM ( 1N,M5001 \leq N, M \leq 500 ), representing size of the matrix, and KK ( 0K51050 \leq K \leq 5*10^5 ) , the number of jumping transformers.

In next KK lines, for each transformer, numbers xx , yy , dd ( d1d \geq 1 ), tt ( 0tN+M20 \leq t \leq N+M-2 ), and ee ( 0e1090 \leq e \leq 10^9 ), representing starting coordinates of transformer, jumping positions distance in pattern described above, time when transformer starts jumping, and energy required to kill it.

It is guaranteed that all 4 of jumping points of the transformers are within matrix coordinates

输出格式

Print single integer, the minimum possible amount of energy wasted, for Blackout to arrive at bottom-right corner.

输入输出样例

  • 输入#1

    3 3 5
    0 1 1 0 7
    1 1 1 0 10
    1 1 1 1 2
    1 1 1 2 2
    0 1 1 2 3
    

    输出#1

    9

说明/提示

If Blackout takes the path from (0, 0) to (2, 0), and then from (2, 0) to (2, 2) he will need to kill the first and third transformer for a total energy cost of 9. There exists no path with less energy value.

首页