#include "wombats.h"
#include <bits/stdc++.h>
#include <utility>
using namespace std;
struct qry{
pair<int,int> pos;
int w;
bool operator<(qry x) const{
return w > x.w;
}
};
int hori[5000][200],verti[5000][200];
int dp[200][5000][200],r,c;
bitset<200> alrdid;
const int big = 1e9+7;
void dij(int a,int b,int in){
priority_queue<qry> pq;
for(int i = 0; i < r; i++)
for(int j = 0; j< c;j++)
dp[in][i][j] = big;
qry tmp;
tmp.pos = {a,b};
tmp.w = 0;
pq.push(tmp);
while(!pq.empty()) {
qry x = pq.top();
pq.pop();
if(dp[in][x.pos.first][x.pos.second] == big) {
dp[in][x.pos.first][x.pos.second] = x.w;
qry sth;
if(x.pos.second!=0) {
sth.pos = {x.pos.first,x.pos.second - 1};
sth.w = hori[sth.pos.first][sth.pos.second] + x.w;
pq.push(sth);
}
if(x.pos.second != c - 1) {
sth.pos = {x.pos.first, x.pos.second + 1};
sth.w = hori[x.pos.first][x.pos.second] + x.w;
pq.push(sth);
}
if(x.pos.first != 0) {
sth.pos = {x.pos.first - 1,x.pos.second};
sth.w = verti[sth.pos.first][sth.pos.second] + x.w;
pq.push(sth);
}
}
}
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
r = R, c= C;
for(int i =0; i < R;i++)
for(int j = 0; j < C;j++)
hori[i][j] = H[i][j], verti[i][j] = V[i][j];
alrdid.reset();
}
void changeH(int P, int Q, int W) {
hori[P][Q] = W;
alrdid.reset();
}
void changeV(int P, int Q, int W) {
verti[P][Q] = W;
alrdid.reset();
}
int escape(int V1, int V2) {
if(!alrdid[V2])
dij(r-1,V2,V2);
alrdid[V2] = 1;
return dp[V2][0][V1];
}
Compilation message
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
15 | int res;
| ^~~
wombats.cpp: In function 'void dij(int, int, int)':
wombats.cpp:23:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
23 | for(int i = 0; i < r; i++)
| ^~~
wombats.cpp:27:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
27 | qry tmp;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
15964 KB |
Output is correct |
2 |
Correct |
37 ms |
15964 KB |
Output is correct |
3 |
Correct |
74 ms |
17488 KB |
Output is correct |
4 |
Correct |
37 ms |
15960 KB |
Output is correct |
5 |
Correct |
41 ms |
15964 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
860 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
856 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
2 ms |
860 KB |
Output is correct |
11 |
Correct |
40 ms |
1728 KB |
Output is correct |
12 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
5456 KB |
Output is correct |
2 |
Correct |
238 ms |
6252 KB |
Output is correct |
3 |
Correct |
202 ms |
6176 KB |
Output is correct |
4 |
Correct |
202 ms |
6228 KB |
Output is correct |
5 |
Correct |
200 ms |
6400 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
93 ms |
984 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
548 ms |
23900 KB |
Output is correct |
2 |
Correct |
956 ms |
23916 KB |
Output is correct |
3 |
Correct |
528 ms |
23900 KB |
Output is correct |
4 |
Correct |
551 ms |
24660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
5396 KB |
Output is correct |
2 |
Correct |
238 ms |
6212 KB |
Output is correct |
3 |
Correct |
204 ms |
6228 KB |
Output is correct |
4 |
Correct |
197 ms |
6228 KB |
Output is correct |
5 |
Correct |
205 ms |
6480 KB |
Output is correct |
6 |
Correct |
536 ms |
23908 KB |
Output is correct |
7 |
Correct |
953 ms |
23920 KB |
Output is correct |
8 |
Correct |
531 ms |
23912 KB |
Output is correct |
9 |
Correct |
542 ms |
24660 KB |
Output is correct |
10 |
Correct |
38 ms |
15964 KB |
Output is correct |
11 |
Correct |
37 ms |
15964 KB |
Output is correct |
12 |
Correct |
73 ms |
17492 KB |
Output is correct |
13 |
Correct |
38 ms |
15960 KB |
Output is correct |
14 |
Correct |
38 ms |
15964 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
1 ms |
860 KB |
Output is correct |
20 |
Correct |
1 ms |
860 KB |
Output is correct |
21 |
Correct |
1 ms |
860 KB |
Output is correct |
22 |
Correct |
2 ms |
860 KB |
Output is correct |
23 |
Correct |
2 ms |
860 KB |
Output is correct |
24 |
Correct |
2 ms |
860 KB |
Output is correct |
25 |
Correct |
39 ms |
1880 KB |
Output is correct |
26 |
Correct |
1 ms |
860 KB |
Output is correct |
27 |
Correct |
125 ms |
964 KB |
Output is correct |
28 |
Runtime error |
5776 ms |
262144 KB |
Execution killed with signal 9 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
5484 KB |
Output is correct |
2 |
Correct |
248 ms |
6392 KB |
Output is correct |
3 |
Correct |
197 ms |
6224 KB |
Output is correct |
4 |
Correct |
198 ms |
6228 KB |
Output is correct |
5 |
Correct |
201 ms |
6484 KB |
Output is correct |
6 |
Correct |
567 ms |
23900 KB |
Output is correct |
7 |
Correct |
1034 ms |
23900 KB |
Output is correct |
8 |
Correct |
577 ms |
23912 KB |
Output is correct |
9 |
Correct |
593 ms |
24652 KB |
Output is correct |
10 |
Correct |
39 ms |
15964 KB |
Output is correct |
11 |
Correct |
39 ms |
15964 KB |
Output is correct |
12 |
Correct |
76 ms |
17616 KB |
Output is correct |
13 |
Correct |
41 ms |
15964 KB |
Output is correct |
14 |
Correct |
39 ms |
15964 KB |
Output is correct |
15 |
Correct |
670 ms |
23760 KB |
Output is correct |
16 |
Runtime error |
13912 ms |
262144 KB |
Execution killed with signal 9 |
17 |
Halted |
0 ms |
0 KB |
- |