Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
B"Vanya is in the palace that can be represented as a grid n xe2 x80 x89 xc3 x97 xe2 x80 x89m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x xe2 x80 x89 xe2 x89 xa4 xe2 x80 x89p xe2 x80 x89- xe2 x80 x891 contains a key that can open any chest of type x xe2 x80 x89+ xe2 x80 x891, and all chests of type 1 are not locked. There is exactly one chest of type p and it contains a treasure. Vanya starts in cell (1, xe2 x80 x891) (top left corner). What is the minimum total distance Vanya has to walk in order to get the treasure? Consider the distance between cell (r1, xe2 x80 x89c1) (the cell in the row r1 and column c1) and (r2, xe2 x80 x89c2) is equal to |r1 xe2 x80 x89- xe2 x80 x89r2| xe2 x80 x89+ xe2 x80 x89|c1 xe2 x80 x89- xe2 x80 x89c2|. The first line of the input contains three integers n, m and p (1 xe2 x80 x89 xe2 x89 xa4 xe2 x80 x89n, xe2 x80 x89m xe2 x80 x89 xe2 x89 xa4 xe2 x80 x89300, xe2 x80 x891 xe2 x80 x89 xe2 x89 xa4 xe2 x80 x89p xe2 x80 x89 xe2 x89 xa4 xe2 x80 x89n xc2 xb7m) -- the number of rows and columns in the table representing the palace and the number of different types of the chests, respectively. Each of the following n lines contains m integers aij (1 xe2 x80 x89 xe2 x89 xa4 xe2 x80 x89aij xe2 x80 x89 xe2 x89 xa4 xe2 x80 x89p) -- the types of the chests in corresponding rooms. It's guaranteed that for each x from 1 to p there is at least one chest of this type (that is, there exists a pair of r and c, such that arc xe2 x80 x89= xe2 x80 x89x). Also, it's guaranteed that there is exactly one chest of type p. Print one integer -- the minimum possible total distance Vanya has to walk in order to get the treasure from the chest of type p. "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
18295873 |
Holidin |
D |
June 8, 2016, 9:34 a.m. |
OK |
Delphi |
TESTS |
86 |
873 |
9113600 |
|
2300 |
18497316 |
yan_lazy |
D |
June 15, 2016, 12:41 p.m. |
OK |
FPC |
TESTS |
86 |
405 |
3788800 |
|
2300 |
19649118 |
WalkingDeade |
D |
Aug. 5, 2016, 9:51 a.m. |
OK |
FPC |
TESTS |
86 |
468 |
3584000 |
|
2300 |
23915584 |
vjudge5 |
D |
Jan. 18, 2017, 6:28 a.m. |
OK |
GNU C++ |
TESTS |
86 |
62 |
6758400 |
|
2300 |
40984411 |
ReaLNero1 |
D |
July 30, 2018, 7:21 p.m. |
OK |
GNU C++ |
TESTS |
86 |
77 |
4608000 |
|
2300 |
20221484 |
Out_of_Cage |
D |
Aug. 29, 2016, 2:21 a.m. |
OK |
GNU C++ |
TESTS |
86 |
93 |
5836800 |
|
2300 |
18358089 |
RNS3 |
D |
June 10, 2016, 12:15 p.m. |
OK |
GNU C++ |
TESTS |
86 |
93 |
7168000 |
|
2300 |
19960930 |
vjudge5 |
D |
Aug. 19, 2016, 9:14 a.m. |
OK |
GNU C++ |
TESTS |
86 |
93 |
7884800 |
|
2300 |
19222876 |
GLK |
D |
July 19, 2016, 2:42 a.m. |
OK |
GNU C++ |
TESTS |
86 |
108 |
6860800 |
|
2300 |
20613085 |
vjudge2 |
D |
Sept. 14, 2016, 11:50 a.m. |
OK |
GNU C++ |
TESTS |
86 |
109 |
4096000 |
|
2300 |
18978687 |
akautomation |
D |
July 9, 2016, 3:17 a.m. |
OK |
GNU C++ |
TESTS |
86 |
109 |
7372800 |
|
2300 |
36426150 |
vjudge1 |
D |
March 20, 2018, 6:48 a.m. |
OK |
GNU C++ |
TESTS |
86 |
109 |
8806400 |
|
2300 |
20138645 |
abhaygarg |
D |
Aug. 24, 2016, 9:56 p.m. |
OK |
GNU C++ |
TESTS |
86 |
109 |
14438400 |
|
2300 |
56769088 |
rainboy |
D |
July 9, 2019, 8:15 p.m. |
OK |
GNU C11 |
TESTS |
86 |
234 |
1433600 |
|
2300 |
18386102 |
Penny_Lane |
D |
June 12, 2016, 7:48 a.m. |
OK |
GNU C++11 |
TESTS |
86 |
77 |
7372800 |
|
2300 |
18386228 |
Penny_Lane |
D |
June 12, 2016, 7:59 a.m. |
OK |
GNU C++11 |
TESTS |
86 |
78 |
7680000 |
|
2300 |
18386230 |
Penny_Lane |
D |
June 12, 2016, 8 a.m. |
OK |
GNU C++11 |
TESTS |
86 |
78 |
7782400 |
|
2300 |
29796521 |
emoairx |
D |
Aug. 26, 2017, 4:14 a.m. |
OK |
GNU C++11 |
TESTS |
86 |
93 |
2764800 |
|
2300 |
18386058 |
Penny_Lane |
D |
June 12, 2016, 7:44 a.m. |
OK |
GNU C++11 |
TESTS |
86 |
93 |
7372800 |
|
2300 |
28715927 |
Dream_Tonight |
D |
July 20, 2017, 7:23 a.m. |
OK |
GNU C++11 |
TESTS |
86 |
93 |
9523200 |
|
2300 |
19414222 |
Xgtao984 |
D |
July 26, 2016, 3:54 a.m. |
OK |
GNU C++11 |
TESTS |
86 |
109 |
6963200 |
|
2300 |
19414239 |
vjudge1 |
D |
July 26, 2016, 3:55 a.m. |
OK |
GNU C++11 |
TESTS |
86 |
109 |
6963200 |
|
2300 |
61187245 |
zxyl |
D |
Sept. 23, 2019, 11:57 p.m. |
OK |
GNU C++11 |
TESTS |
86 |
109 |
7270400 |
|
2300 |
23064213 |
javacoder1 |
D |
Dec. 17, 2016, 5:42 p.m. |
OK |
GNU C++11 |
TESTS |
86 |
109 |
8089600 |
|
2300 |
32833871 |
eric |
D |
Dec. 1, 2017, 3:29 p.m. |
OK |
GNU C++14 |
TESTS |
86 |
124 |
6656000 |
|
2300 |
29795826 |
lllllllllllllllllllllll |
D |
Aug. 26, 2017, 3:10 a.m. |
OK |
GNU C++14 |
TESTS |
86 |
139 |
4403200 |
|
2300 |
35179819 |
waynetuinfor |
D |
Feb. 12, 2018, 1:52 p.m. |
OK |
GNU C++14 |
TESTS |
86 |
139 |
6656000 |
|
2300 |
21198078 |
Steven_Chen |
D |
Oct. 4, 2016, 11:28 p.m. |
OK |
GNU C++14 |
TESTS |
86 |
140 |
4608000 |
|
2300 |
31376975 |
Dalgerok |
D |
Oct. 15, 2017, 8:17 p.m. |
OK |
GNU C++14 |
TESTS |
86 |
140 |
5632000 |
|
2300 |
23520527 |
akaring |
D |
Jan. 3, 2017, 4:37 p.m. |
OK |
GNU C++14 |
TESTS |
86 |
140 |
7782400 |
|
2300 |
36895132 |
farukkastamonuda |
D |
April 3, 2018, 7:09 a.m. |
OK |
GNU C++14 |
TESTS |
86 |
140 |
8704000 |
|
2300 |
37750411 |
3015218054 |
D |
April 30, 2018, 2:30 p.m. |
OK |
GNU C++14 |
TESTS |
86 |
171 |
8294400 |
|
2300 |
31360724 |
ITer |
D |
Oct. 15, 2017, 10:22 a.m. |
OK |
GNU C++14 |
TESTS |
86 |
186 |
5529600 |
|
2300 |
35226887 |
n_dao107 |
D |
Feb. 14, 2018, 9:22 a.m. |
OK |
GNU C++14 |
TESTS |
86 |
186 |
6656000 |
|
2300 |
58336848 |
Phortox |
D |
Aug. 5, 2019, 11:48 a.m. |
OK |
GNU C++17 |
TESTS |
86 |
93 |
5734400 |
|
2300 |
58336767 |
Phortox |
D |
Aug. 5, 2019, 11:46 a.m. |
OK |
GNU C++17 |
TESTS |
86 |
93 |
5734400 |
|
2300 |
44454858 |
EdmonDantes |
D |
Oct. 17, 2018, 5:27 p.m. |
OK |
GNU C++17 |
TESTS |
86 |
156 |
5120000 |
|
2300 |
65089451 |
gamegame |
D |
Nov. 15, 2019, 6:10 p.m. |
OK |
GNU C++17 |
TESTS |
86 |
171 |
3993600 |
|
2300 |
69674700 |
toadehu |
D |
Jan. 28, 2020, 1:57 p.m. |
OK |
GNU C++17 |
TESTS |
86 |
171 |
4300800 |
|
2300 |
54813374 |
Grzmot |
D |
May 29, 2019, 6:13 p.m. |
OK |
GNU C++17 |
TESTS |
86 |
171 |
6758400 |
|
2300 |
56758409 |
buerdepepeqi |
D |
July 9, 2019, 2:49 p.m. |
OK |
GNU C++17 |
TESTS |
86 |
171 |
11776000 |
|
2300 |
56756766 |
buerdepepeqi |
D |
July 9, 2019, 2:14 p.m. |
OK |
GNU C++17 |
TESTS |
86 |
171 |
11776000 |
|
2300 |
58965467 |
probassassin |
D |
Aug. 17, 2019, 5:34 p.m. |
OK |
GNU C++17 |
TESTS |
86 |
171 |
25395200 |
|
2300 |
43360650 |
crathva |
D |
Sept. 24, 2018, 9:04 a.m. |
OK |
GNU C++17 |
TESTS |
86 |
233 |
4403200 |
|
2300 |
67998767 |
ypa |
D |
Dec. 31, 2019, 9:39 a.m. |
OK |
Java 11 |
TESTS |
86 |
545 |
5734400 |
|
2300 |
19017482 |
WonderMouse |
D |
July 11, 2016, 12:54 a.m. |
OK |
Java 7 |
TESTS |
86 |
904 |
0 |
|
2300 |
19138671 |
228 |
D |
July 15, 2016, 1:05 a.m. |
OK |
Java 7 |
TESTS |
86 |
1091 |
5427200 |
|
2300 |
18401867 |
sharingan |
D |
June 12, 2016, 10:51 p.m. |
OK |
Java 8 |
TESTS |
86 |
327 |
38502400 |
|
2300 |
56769089 |
Dukkha |
D |
July 9, 2019, 8:15 p.m. |
OK |
Java 8 |
TESTS |
86 |
358 |
0 |
|
2300 |
19012453 |
WonderMouse |
D |
July 10, 2016, 3:41 p.m. |
OK |
Java 8 |
TESTS |
86 |
389 |
0 |
|
2300 |
18586842 |
asdfasdfasdf |
D |
June 18, 2016, 8:46 p.m. |
OK |
Java 8 |
TESTS |
86 |
405 |
5222400 |
|
2300 |
18586570 |
asdfasdfasdf |
D |
June 18, 2016, 8:22 p.m. |
OK |
Java 8 |
TESTS |
86 |
405 |
5529600 |
|
2300 |
18586866 |
asdfasdfasdf |
D |
June 18, 2016, 8:49 p.m. |
OK |
Java 8 |
TESTS |
86 |
421 |
5222400 |
|
2300 |
18586178 |
asdfasdfasdf |
D |
June 18, 2016, 7:45 p.m. |
OK |
Java 8 |
TESTS |
86 |
421 |
16179200 |
|
2300 |
18586185 |
asdfasdfasdf |
D |
June 18, 2016, 7:45 p.m. |
OK |
Java 8 |
TESTS |
86 |
452 |
16179200 |
|
2300 |
20269965 |
megaspazz |
D |
Aug. 30, 2016, 4:49 a.m. |
OK |
Java 8 |
TESTS |
86 |
717 |
5017600 |
|
2300 |
19170055 |
hama-du |
D |
July 16, 2016, 9:01 a.m. |
OK |
Java 8 |
TESTS |
86 |
794 |
0 |
|
2300 |
18291918 |
renadeen |
D |
June 8, 2016, 12:52 a.m. |
OK |
MS C# |
TESTS |
86 |
997 |
25702400 |
|
2300 |
18381460 |
c4big2 |
D |
June 11, 2016, 9:25 p.m. |
OK |
MS C++ |
TESTS |
86 |
249 |
6860800 |
|
2300 |
18409070 |
xiaoyu.du |
D |
June 13, 2016, 9:25 a.m. |
OK |
MS C++ |
TESTS |
86 |
327 |
7270400 |
|
2300 |
32145838 |
Ronnie007 |
D |
Nov. 8, 2017, 7:55 p.m. |
OK |
MS C++ |
TESTS |
86 |
358 |
4710400 |
|
2300 |
18545037 |
AU.Bahosain |
D |
June 17, 2016, 2:39 p.m. |
OK |
MS C++ |
TESTS |
86 |
592 |
5632000 |
|
2300 |
53769517 |
vjudge4 |
D |
May 5, 2019, 3:44 a.m. |
OK |
MS C++ |
TESTS |
86 |
873 |
5324800 |
|
2300 |
21613571 |
AWCXV |
D |
Oct. 20, 2016, 9:41 a.m. |
OK |
MS C++ |
TESTS |
86 |
904 |
6963200 |
|
2300 |
34274233 |
ys1468362286 |
D |
Jan. 18, 2018, 11:32 a.m. |
OK |
MS C++ |
TESTS |
86 |
904 |
8192000 |
|
2300 |
34605422 |
vjudge2 |
D |
Jan. 27, 2018, 12:30 p.m. |
OK |
MS C++ |
TESTS |
86 |
935 |
8192000 |
|
2300 |
34275804 |
vjudge4 |
D |
Jan. 18, 2018, 12:43 p.m. |
OK |
MS C++ |
TESTS |
86 |
936 |
8192000 |
|
2300 |
remove filters
Back to search problems