#include "wombats.h"
#include <vector>
#include <iostream>
#include <queue>
typedef long long ll;
#define F first
#define S second
using namespace std;
int H[5000][200];
int V[5000][200];
int R,C;
int sum = 0;
int sub2 = 0;
int dp[25][25];
void calc2(int V1){
priority_queue<pair<int,pair<int,int>>> pq;
pq.push({0,{0,V1}});
int dis[25][25];
int vis[25][25];
for(int i=0;i<25;i++)for(int j=0;j<25;j++)dis[i][j] = 2e9;
for(int i=0;i<25;i++)for(int j=0;j<25;j++)vis[i][j] = 0;
dis[0][V1] = 0;
while(!pq.empty()){
int y = pq.top().S.F;
int x = pq.top().S.S;
pq.pop();
if(vis[y][x])continue;
vis[y][x] = 1;
if(x > 0 && (dis[y][x] + H[y][x-1] < dis[y][x-1])){
// cerr << x << "," << y << " " << dis[y][x] << " " << H[y][x-1] << " L\n";
dis[y][x-1] = dis[y][x] + H[y][x-1];
pq.push({-dis[y][x-1],{y,x-1}});
}
if(x < (C-1) && (dis[y][x] + H[y][x] < dis[y][x+1])){
// cerr << x << "," << y << " " << dis[y][x] << " " << H[y][x] << " R\n";
dis[y][x+1] = dis[y][x] + H[y][x];
pq.push({-dis[y][x+1],{y,x+1}});
}
if(y < (R-1) && (dis[y][x] + V[y][x] < dis[y+1][x])){
// cerr << x << "," << y << " " << dis[y][x] << " " << V[y][x] << " D\n";
dis[y+1][x] = dis[y][x] + V[y][x];
pq.push({-dis[y+1][x],{y+1,x}});
}
}
// for(int i=0;i<R;i++){
// for(int j=0;j<C;j++){
// cerr << dis[i][j] << " ";
// }cerr << endl;
// }cerr << endl;
for(int i=0;i<25;i++)dp[V1][i] = dis[R-1][i];
}
void init(int r, int c, int h[5000][200], int v[5000][200]) {
R = r;
C = c;
if(R<=20 && C<= 20)sub2 = 1;
for(int i=0;i<5000;i++)for(int j=0;j<200;j++)H[i][j] = h[i][j];
for(int i=0;i<5000;i++)for(int j=0;j<200;j++)V[i][j] = v[i][j];
for(int i=0;i<5000;i++)for(int j=0;j<200;j++)sum += V[i][j];
if(sub2){
for(int i=0;i<R;i++)calc2(i);
}
}
void changeH(int P, int Q, int W) {
H[P][Q] = W;
}
void changeV(int P, int Q, int W) {
sum -= V[P][Q];
sum += W;
V[P][Q] = W;
}
int escape(int V1, int V2) {
if(C == 1){
return sum;
}
if(sub2){
return dp[V1][V2];
}
priority_queue<pair<int,pair<int,int>>> pq;
pq.push({0,{0,V1}});
int dis[5005][205];
int vis[5005][205];
for(int i=0;i<5005;i++)for(int j=0;j<205;j++)dis[i][j] = 2e9;
for(int i=0;i<5005;i++)for(int j=0;j<205;j++)vis[i][j] = 0;
dis[0][V1] = 0;
while(!pq.empty()){
int y = pq.top().S.F;
int x = pq.top().S.S;
pq.pop();
if(vis[y][x])continue;
vis[y][x] = 1;
if(x > 0 && (dis[y][x] + H[y][x-1] < dis[y][x-1])){
// cerr << x << "," << y << " " << dis[y][x] << " " << H[y][x-1] << " L\n";
dis[y][x-1] = dis[y][x] + H[y][x-1];
pq.push({-dis[y][x-1],{y,x-1}});
}
if(x < (C-1) && (dis[y][x] + H[y][x] < dis[y][x+1])){
// cerr << x << "," << y << " " << dis[y][x] << " " << H[y][x] << " R\n";
dis[y][x+1] = dis[y][x] + H[y][x];
pq.push({-dis[y][x+1],{y,x+1}});
}
if(y < (R-1) && (dis[y][x] + V[y][x] < dis[y+1][x])){
// cerr << x << "," << y << " " << dis[y][x] << " " << V[y][x] << " D\n";
dis[y+1][x] = dis[y][x] + V[y][x];
pq.push({-dis[y+1][x],{y+1,x}});
}
}
// for(int i=0;i<R;i++){
// for(int j=0;j<C;j++){
// cerr << dis[i][j] << " ";
// }cerr << endl;
// }cerr << endl;
return dis[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;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
20060 KB |
Output is correct |
2 |
Correct |
22 ms |
20244 KB |
Output is correct |
3 |
Correct |
4608 ms |
22868 KB |
Output is correct |
4 |
Correct |
25 ms |
20312 KB |
Output is correct |
5 |
Correct |
21 ms |
20100 KB |
Output is correct |
6 |
Correct |
8 ms |
16216 KB |
Output is correct |
7 |
Correct |
8 ms |
16220 KB |
Output is correct |
8 |
Correct |
8 ms |
16172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
16220 KB |
Output is correct |
2 |
Correct |
8 ms |
16216 KB |
Output is correct |
3 |
Correct |
8 ms |
16216 KB |
Output is correct |
4 |
Correct |
18 ms |
16356 KB |
Output is correct |
5 |
Correct |
18 ms |
16216 KB |
Output is correct |
6 |
Correct |
20 ms |
16220 KB |
Output is correct |
7 |
Correct |
19 ms |
16220 KB |
Output is correct |
8 |
Correct |
17 ms |
16220 KB |
Output is correct |
9 |
Incorrect |
18 ms |
16220 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
155 ms |
16472 KB |
Output is correct |
2 |
Correct |
211 ms |
16700 KB |
Output is correct |
3 |
Correct |
152 ms |
16476 KB |
Output is correct |
4 |
Correct |
158 ms |
16472 KB |
Output is correct |
5 |
Correct |
152 ms |
16544 KB |
Output is correct |
6 |
Correct |
9 ms |
16220 KB |
Output is correct |
7 |
Correct |
8 ms |
16220 KB |
Output is correct |
8 |
Correct |
8 ms |
16220 KB |
Output is correct |
9 |
Correct |
215 ms |
16456 KB |
Output is correct |
10 |
Incorrect |
9 ms |
16220 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
824 ms |
24156 KB |
Output is correct |
2 |
Correct |
1343 ms |
24172 KB |
Output is correct |
3 |
Correct |
829 ms |
24156 KB |
Output is correct |
4 |
Execution timed out |
20049 ms |
24612 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
154 ms |
16544 KB |
Output is correct |
2 |
Correct |
211 ms |
16692 KB |
Output is correct |
3 |
Correct |
158 ms |
16552 KB |
Output is correct |
4 |
Correct |
153 ms |
16476 KB |
Output is correct |
5 |
Correct |
156 ms |
16476 KB |
Output is correct |
6 |
Correct |
829 ms |
24156 KB |
Output is correct |
7 |
Correct |
1324 ms |
24152 KB |
Output is correct |
8 |
Correct |
840 ms |
24176 KB |
Output is correct |
9 |
Execution timed out |
20065 ms |
24604 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
16472 KB |
Output is correct |
2 |
Correct |
208 ms |
16692 KB |
Output is correct |
3 |
Correct |
158 ms |
16472 KB |
Output is correct |
4 |
Correct |
156 ms |
16476 KB |
Output is correct |
5 |
Correct |
155 ms |
16476 KB |
Output is correct |
6 |
Correct |
826 ms |
24156 KB |
Output is correct |
7 |
Correct |
1341 ms |
24168 KB |
Output is correct |
8 |
Correct |
870 ms |
24172 KB |
Output is correct |
9 |
Execution timed out |
20050 ms |
24596 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |