#pragma GCC optimize("O3")
#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[5000][200],r,c;
int ans[200][200];
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[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[x.pos.first][x.pos.second] == big) {
dp[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);
}
}
}
for(int i = 0; i < c;i++)
ans[in][i] = dp[0][i];
}
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 ans[V2][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:26:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
26 | for(int i = 0; i < r; i++)
| ^~~
wombats.cpp:30:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
30 | qry tmp;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
15964 KB |
Output is correct |
2 |
Correct |
40 ms |
15964 KB |
Output is correct |
3 |
Correct |
79 ms |
17488 KB |
Output is correct |
4 |
Correct |
44 ms |
16100 KB |
Output is correct |
5 |
Correct |
48 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
352 KB |
Output is correct |
11 |
Correct |
51 ms |
1364 KB |
Output is correct |
12 |
Correct |
2 ms |
352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
860 KB |
Output is correct |
2 |
Correct |
247 ms |
1216 KB |
Output is correct |
3 |
Correct |
224 ms |
944 KB |
Output is correct |
4 |
Correct |
221 ms |
924 KB |
Output is correct |
5 |
Correct |
195 ms |
1112 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
110 ms |
924 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
522 ms |
19804 KB |
Output is correct |
2 |
Correct |
1016 ms |
19996 KB |
Output is correct |
3 |
Correct |
546 ms |
19984 KB |
Output is correct |
4 |
Correct |
561 ms |
20772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
880 KB |
Output is correct |
2 |
Correct |
242 ms |
1220 KB |
Output is correct |
3 |
Correct |
226 ms |
1104 KB |
Output is correct |
4 |
Correct |
196 ms |
944 KB |
Output is correct |
5 |
Correct |
224 ms |
856 KB |
Output is correct |
6 |
Correct |
519 ms |
19984 KB |
Output is correct |
7 |
Correct |
973 ms |
20008 KB |
Output is correct |
8 |
Correct |
556 ms |
19984 KB |
Output is correct |
9 |
Correct |
585 ms |
20556 KB |
Output is correct |
10 |
Correct |
43 ms |
15964 KB |
Output is correct |
11 |
Correct |
42 ms |
16084 KB |
Output is correct |
12 |
Correct |
84 ms |
17628 KB |
Output is correct |
13 |
Correct |
39 ms |
16080 KB |
Output is correct |
14 |
Correct |
41 ms |
15964 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
76 ms |
1368 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
93 ms |
904 KB |
Output is correct |
28 |
Execution timed out |
20029 ms |
19976 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
157 ms |
936 KB |
Output is correct |
2 |
Correct |
249 ms |
1256 KB |
Output is correct |
3 |
Correct |
227 ms |
860 KB |
Output is correct |
4 |
Correct |
205 ms |
896 KB |
Output is correct |
5 |
Correct |
199 ms |
896 KB |
Output is correct |
6 |
Correct |
527 ms |
19804 KB |
Output is correct |
7 |
Correct |
969 ms |
20004 KB |
Output is correct |
8 |
Correct |
505 ms |
19804 KB |
Output is correct |
9 |
Correct |
574 ms |
20764 KB |
Output is correct |
10 |
Correct |
38 ms |
15964 KB |
Output is correct |
11 |
Correct |
38 ms |
16080 KB |
Output is correct |
12 |
Correct |
75 ms |
17488 KB |
Output is correct |
13 |
Correct |
37 ms |
15964 KB |
Output is correct |
14 |
Correct |
40 ms |
16132 KB |
Output is correct |
15 |
Correct |
654 ms |
19916 KB |
Output is correct |
16 |
Execution timed out |
20050 ms |
20148 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |