5/13/25, 11:54 AM Problem - 1517D - Codeforces
|
I_Love_HoangTrang | Logout
HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP
PROBLEMS SUBMIT STATUS STANDINGS CUSTOM TEST
Contest 2050 and Codeforces
D. Explorer Space Round 718 (Div. 1 + Div. 2)
time limit per test: 2 seconds Finished
memory limit per test: 256 megabytes Practice
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 × m . The
set of vertices is {(i, j)|1 ≤ i ≤ n, 1 ≤ j ≤ m}. Two vertices (i1 , j1 ) and (i2 , j2 ) are → Virtual participation
connected by an edge if and only if |i1 − i2 | + |j1 − j2 | = 1 .
Virtual contest is a way to take part in past
contest, as close as possible to participation
At each step, you can walk to any vertex connected by an edge with your current vertex. On each on time. It is supported only ICPC mode for
edge, there are some number of exhibits. Since you already know all the exhibits, whenever you virtual contests. If you've seen these
problems, a virtual contest is not for you -
go through an edge containing x exhibits, your boredness increases by x . solve these problems in the archive. If you
just want to solve some problem from a
For each starting vertex (i, j) , please answer the following question: What is the minimum contest, a virtual contest is not for you -
solve this problem in the archive. Never use
possible boredness if you walk from (i, j) and go back to it after exactly k steps? someone else's code, read the tutorials or
communicate with other person during a
You can use any edge for multiple times but the boredness on those edges are also counted for virtual contest.
multiple times. At each step, you cannot stay on your current vertex. You also cannot change
Start virtual contest
direction while going through an edge. Before going back to your starting vertex (i, j) after k
steps, you can visit (i, j) (or not) freely.
Input → Clone Contest to Mashup
The first line contains three integers n, m and k (2 ≤ n, m ≤ 500, 1 ≤ k ≤ 20 ).
You can clone this contest to a mashup.
The j -th number (1 ≤ j ≤ m − 1 ) in the i -th line of the following n lines is the number of Clone Contest
exibits on the edge between vertex (i, j) and vertex (i, j + 1).
The j -th number (1 ≤ j ≤ m) in the i -th line of the following n − 1 lines is the number of
→ Submit?
exibits on the edge between vertex (i, j) and vertex (i + 1, j).
The number of exhibits on each edge is an integer between 1 and 106 . Language: GNU G++17 7.3.0
Choose
Output file:
Choose File No file chosen
Output n lines with m numbers each. The j -th number in the i -th line, answer ij , should be the
minimum possible boredness if you walk from (i, j) and go back to it after exactly k steps. Submit
If you cannot go back to vertex (i, j) after exactly k steps, answer ij should be −1.
→ Problem tags
Examples
input Copy dp graphs shortest paths *1800
No tag edit access
3 3 10
1 1
1 1
1 1 → Contest materials
1 1 1
1 1 1 Announcement (en)
output Copy Tutorial (en)
10 10 10
10 10 10
10 10 10
input Copy
2 2 4
1
3
4 2
output Copy
4 4
10 6
input Copy
https://codeforces.com/problemset/problem/1517/D 1/2
5/13/25, 11:54 AM Problem - 1517D - Codeforces
2 2 3
1
2
3 4
output Copy
-1 -1
-1 -1
Note
In the first example, the answer is always 10 no matter how you walk.
In the second example, answer 21 = 10 , the path is
(2, 1) → (1, 1) → (1, 2) → (2, 2) → (2, 1) , the boredness is 4 + 1 + 2 + 3 = 10 .
Codeforces (c) Copyright 2010-2025 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: May/13/2025 11:54:30UTC+7 (k1).
Desktop version, switch to mobile version.
Privacy Policy | Terms and Conditions
Supported by
https://codeforces.com/problemset/problem/1517/D 2/2