#include "wombats.h"
#include <bits/stdc++.h>
#define R 5000
#define C 100
using namespace std;
int dp[C][R][C];
int r,c;
int h[R][C];
int v[R][C];
int preh[R][C];
int dist[R][C];
void build(){
if(c > 20)return;
for(int i = 0;i<r;i++){
for(int j = 0;j<c;j++){
preh[i][j] = h[i][j] + (j == 0?0:preh[i][j-1]);
}
}
for(int x = 0;x<c;x++){
for(int i = 0;i<r;i++){
for(int j = 0;j<c;j++){
dp[x][i][j] = 1e9;
}
}
for(int i = 0;i<c;i++){
dp[x][0][i] = abs((x == 0?0:preh[0][x-1]) - (i == 0?0:preh[0][i-1]));
}
for(int i = 0;i<r-1;i++){
for(int j = 0;j<c;j++){
for(int d = 0;d<c;d++){
int cost = v[i][j];
cost += abs((j == 0?0:preh[i+1][j-1]) - (d == 0?0:preh[i+1][d-1]));
dp[x][i+1][d] = min(dp[x][i+1][d], dp[x][i][j] + cost);
}
}
}
}
}
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++){
h[i][j] = h_[i][j];
v[i][j] = v_[i][j];
}
}
build();
}
void changeH(int p, int q, int w) {
h[p][q] = w;
build();
}
void changeV(int p, int q, int w) {
v[p][q] = w;
build();
}
int escape(int v1, int v2) {
if(c > 20){
for(int i = 0;i<r;i++){
for(int j = 0;j<c;j++){
dist[i][j] = 1e9;
}
}
dist[0][v1] = 0;
priority_queue<pair<int,pair<int,int>>> q;
q.push({0,{0,v1}});
while(q.size()){
auto tp = q.top();
q.pop();
tp.first *= -1;
int x = tp.second.first;
int y = tp.second.second;
if(dist[x][y] != tp.first)
continue;
if(x + 1 != r && dist[x+1][y] > dist[x][y] + v[x][y]){
dist[x+1][y] = dist[x][y] + v[x][y];
q.push({-dist[x+1][y],{x+1,y}});
}
if(y + 1 != c && dist[x][y+1] > dist[x][y] + h[x][y]){
dist[x][y+1] = dist[x][y] + h[x][y];
q.push({-dist[x][y+1],{x,y+1}});
}
if(y - 1 != -1 && dist[x][y-1] > dist[x][y] + h[x][y-1]){
dist[x][y-1] = dist[x][y] + h[x][y-1];
q.push({-dist[x][y-1],{x,y-1}});
}
}
return dist[r-1][v2];
}
return dp[v1][r-1][v2];
}
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;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
11988 KB |
Output is correct |
2 |
Correct |
40 ms |
11988 KB |
Output is correct |
3 |
Correct |
103 ms |
13572 KB |
Output is correct |
4 |
Correct |
39 ms |
12052 KB |
Output is correct |
5 |
Correct |
35 ms |
11988 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
66 ms |
1632 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
126 ms |
608 KB |
Output is correct |
2 |
Correct |
202 ms |
888 KB |
Output is correct |
3 |
Correct |
123 ms |
696 KB |
Output is correct |
4 |
Correct |
125 ms |
720 KB |
Output is correct |
5 |
Correct |
124 ms |
696 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
205 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
17908 KB |
Output is correct |
2 |
Correct |
71 ms |
17920 KB |
Output is correct |
3 |
Correct |
71 ms |
17916 KB |
Output is correct |
4 |
Correct |
171 ms |
18632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
596 KB |
Output is correct |
2 |
Correct |
225 ms |
856 KB |
Output is correct |
3 |
Correct |
122 ms |
596 KB |
Output is correct |
4 |
Correct |
121 ms |
596 KB |
Output is correct |
5 |
Correct |
121 ms |
708 KB |
Output is correct |
6 |
Correct |
81 ms |
17944 KB |
Output is correct |
7 |
Correct |
86 ms |
17876 KB |
Output is correct |
8 |
Correct |
105 ms |
17988 KB |
Output is correct |
9 |
Correct |
103 ms |
19280 KB |
Output is correct |
10 |
Correct |
31 ms |
11988 KB |
Output is correct |
11 |
Correct |
29 ms |
11988 KB |
Output is correct |
12 |
Correct |
104 ms |
14864 KB |
Output is correct |
13 |
Correct |
40 ms |
11988 KB |
Output is correct |
14 |
Correct |
28 ms |
11988 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
696 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
1 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
564 KB |
Output is correct |
25 |
Correct |
65 ms |
2996 KB |
Output is correct |
26 |
Correct |
1 ms |
596 KB |
Output is correct |
27 |
Correct |
197 ms |
724 KB |
Output is correct |
28 |
Execution timed out |
20059 ms |
17616 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
608 KB |
Output is correct |
2 |
Correct |
195 ms |
832 KB |
Output is correct |
3 |
Correct |
123 ms |
692 KB |
Output is correct |
4 |
Correct |
126 ms |
696 KB |
Output is correct |
5 |
Correct |
123 ms |
692 KB |
Output is correct |
6 |
Correct |
83 ms |
17876 KB |
Output is correct |
7 |
Correct |
73 ms |
17876 KB |
Output is correct |
8 |
Correct |
83 ms |
18120 KB |
Output is correct |
9 |
Correct |
142 ms |
19296 KB |
Output is correct |
10 |
Correct |
30 ms |
11968 KB |
Output is correct |
11 |
Correct |
37 ms |
12080 KB |
Output is correct |
12 |
Correct |
94 ms |
14820 KB |
Output is correct |
13 |
Correct |
31 ms |
12092 KB |
Output is correct |
14 |
Correct |
30 ms |
11988 KB |
Output is correct |
15 |
Incorrect |
214 ms |
22168 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |