CF1517D.Explorer Space

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are wandering in the explorer space of the 2050 Conference.

The explorer space can be viewed as an undirected weighted grid graph with size n×mn\times m. The set of vertices is (i,j)∣1≤i≤n,1≤j≤m{(i, j)|1\le i\le n, 1\le j\le m}. Two vertices (i1,j1)(i_1,j_1) and (i2,j2)(i_2, j_2) are connected by an edge if and only if ∣i1−i2∣+∣j1−j2∣=1|i_1-i_2|+|j_1-j_2|=1.

At each step, you can walk to any vertex connected by an edge with your current vertex. On each edge, there are some number of exhibits. Since you already know all the exhibits, whenever you go through an edge containing xx exhibits, your boredness increases by xx.

For each starting vertex (i,j)(i, j), please answer the following question: What is the minimum possible boredness if you walk from (i,j)(i, j) and go back to it after exactly kk steps?

You can use any edge for multiple times but the boredness on those edges are also counted for multiple times. At each step, you cannot stay on your current vertex. You also cannot change direction while going through an edge. Before going back to your starting vertex (i,j)(i, j) after kk steps, you can visit (i,j)(i, j) (or not) freely.

你正在 2050 大会的探索空间中漫游。

该探索空间可视为一个大小为 n×mn\times m 的无向带权网格图。其顶点集为 (i,j)∣1≤i≤n, 1≤j≤m{(i, j)\mid 1\le i\le n,\ 1\le j\le m}。当且仅当 ∣i1−i2∣+∣j1−j2∣=1|i_1-i_2|+|j_1-j_2|=1 时,两个顶点 (i1,j1)(i_1,j_1) 与 (i2,j2)(i_2, j_2) 之间存在一条边。

每一步,你均可移动至与当前顶点通过一条边相连的任意顶点。每条边上陈列着若干展品。由于你已熟知所有展品,因此每当经过一条包含 xx 件展品的边时,你的无聊值便会增加 xx。

对每个起始顶点 (i,j)(i, j),请回答如下问题:从 (i,j)(i, j) 出发,恰好经过 kk 步后返回 (i,j)(i, j),所能达到的最小无聊值是多少?

同一条边可被多次使用,但每次经过该边时,其对应的无聊值均需重复计入。每一步中,你不能停留在当前顶点;在穿过一条边的过程中,也不能改变方向。在第 kk 步结束并返回起始顶点 (i,j)(i, j) 之前,你可以自由地(或不)再次访问 (i,j)(i, j)。

输入格式

The first line contains three integers nn, mm and kk (2≤n,m≤500,1≤k≤202\leq n, m\leq 500, 1\leq k\leq 20).

The jj-th number (1≤j≤m−11\le j \le m - 1) in the ii-th line of the following nn lines is the number of exibits on the edge between vertex (i,j)(i, j) and vertex (i,j+1)(i, j+1).

The jj-th number (1≤j≤m1\le j\le m) in the ii-th line of the following n−1n-1 lines is the number of exibits on the edge between vertex (i,j)(i, j) and vertex (i+1,j)(i+1, j).

The number of exhibits on each edge is an integer between 11 and 10610^6.

第一行包含三个整数 nn、mm 和 kk(2≤n,m≤5002\leq n, m\leq 500,1≤k≤201\leq k\leq 20)。

接下来 nn 行中,第 ii 行的第 jj 个数(1≤j≤m−11\le j \le m - 1)表示顶点 (i,j)(i, j) 与顶点 (i,j+1)(i, j+1) 之间边上的展品数量。

再接下来 n−1n-1 行中,第 ii 行的第 jj 个数(1≤j≤m1\le j\le m)表示顶点 (i,j)(i, j) 与顶点 (i+1,j)(i+1, j) 之间边上的展品数量。

每条边上的展品数量均为介于 11 到 10610^6 之间的整数。

输出格式

Output nn lines with mm numbers each. The jj-th number in the ii-th line, answerijanswer_{ij}, should be the minimum possible boredness if you walk from (i,j)(i, j) and go back to it after exactly kk steps.

If you cannot go back to vertex (i,j)(i, j) after exactly kk steps, answerijanswer_{ij} should be −1-1.

输出 nn 行,每行 mm 个数。第 ii 行第 jj 个数 answerijanswer_{ij} 应为:从顶点 (i,j)(i, j) 出发,恰好经过 kk 步后返回 (i,j)(i, j) 所能得到的最小可能的“无聊度”。

若无法恰好经过 kk 步后回到顶点 (i,j)(i, j),则 answerijanswer_{ij} 应为 −1-1。

输入输出样例

  • 输入#1

    3 3 10
    1 1
    1 1
    1 1
    1 1 1
    1 1 1

    输出#1

    10 10 10
    10 10 10
    10 10 10
  • 输入#2

    2 2 4
    1
    3
    4 2

    输出#2

    4 4
    10 6
  • 输入#3

    2 2 3
    1
    2
    3 4

    输出#3

    -1 -1
    -1 -1

说明/提示

In the first example, the answer is always 1010 no matter how you walk.

In the second example, answer21=10answer_{21} = 10, the path is (2,1)→(1,1)→(1,2)→(2,2)→(2,1)(2,1) \to (1,1) \to (1,2) \to (2,2) \to (2,1), the boredness is 4+1+2+3=104 + 1 + 2 + 3 = 10.

在第一个例子中,无论你如何行走,答案始终为 1010。

在第二个例子中,answer21=10answer_{21} = 10,路径为 (2,1)→(1,1)→(1,2)→(2,2)→(2,1)(2,1) \to (1,1) \to (1,2) \to (2,2) \to (2,1),无聊值为 4+1+2+3=104 + 1 + 2 + 3 = 10。

输入解题思路,AI测评打分。不知道怎么写?

首页