#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 dp[205][205];
int need = 0;
void calc2(int V1){
priority_queue<pair<int,pair<int,int>>> pq;
pq.push({0,{0,V1}});
int dis[R+5][C+5];
int vis[R+5][C+5];
for(int i=0;i<R+5;i++)for(int j=0;j<C+5;j++)dis[i][j] = 2e9;
for(int i=0;i<R+5;i++)for(int j=0;j<C+5;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<R+5;i++)dp[V1][i] = dis[R-1][i];
}
void calibrate(){
if(C==1)return;
need = 0;
for(int i=0;i<C+5;i++)calc2(i);
}
void init(int r, int c, int h[5000][200], int v[5000][200]) {
R = r;
C = c;
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];
need = 1;
}
void changeH(int P, int Q, int W) {
H[P][Q] = W;
need = 1;
}
void changeV(int P, int Q, int W) {
sum -= V[P][Q];
sum += W;
V[P][Q] = W;
need = 1;
}
int escape(int V1, int V2) {
if(C == 1){
return sum;
}
if(true){
if(need == 1)calibrate();
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 |
6 ms |
12124 KB |
Output is correct |
2 |
Correct |
7 ms |
12216 KB |
Output is correct |
3 |
Correct |
67 ms |
14792 KB |
Output is correct |
4 |
Correct |
7 ms |
12124 KB |
Output is correct |
5 |
Correct |
10 ms |
12124 KB |
Output is correct |
6 |
Correct |
4 ms |
8120 KB |
Output is correct |
7 |
Correct |
5 ms |
9816 KB |
Output is correct |
8 |
Correct |
5 ms |
9820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8284 KB |
Output is correct |
2 |
Correct |
5 ms |
8260 KB |
Output is correct |
3 |
Correct |
5 ms |
9820 KB |
Output is correct |
4 |
Correct |
8 ms |
8324 KB |
Output is correct |
5 |
Correct |
6 ms |
10332 KB |
Output is correct |
6 |
Correct |
6 ms |
8280 KB |
Output is correct |
7 |
Correct |
7 ms |
8284 KB |
Output is correct |
8 |
Correct |
7 ms |
10332 KB |
Output is correct |
9 |
Correct |
7 ms |
10304 KB |
Output is correct |
10 |
Correct |
5 ms |
8284 KB |
Output is correct |
11 |
Correct |
46 ms |
12652 KB |
Output is correct |
12 |
Correct |
6 ms |
8256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
643 ms |
10588 KB |
Output is correct |
2 |
Correct |
9625 ms |
10828 KB |
Output is correct |
3 |
Correct |
6341 ms |
10644 KB |
Output is correct |
4 |
Correct |
6916 ms |
12216 KB |
Output is correct |
5 |
Correct |
6660 ms |
12216 KB |
Output is correct |
6 |
Correct |
3 ms |
9820 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
6 ms |
9816 KB |
Output is correct |
9 |
Correct |
4245 ms |
12280 KB |
Output is correct |
10 |
Correct |
3 ms |
11868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
20 ms |
33028 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
603 ms |
12120 KB |
Output is correct |
2 |
Correct |
9443 ms |
12532 KB |
Output is correct |
3 |
Correct |
6152 ms |
12124 KB |
Output is correct |
4 |
Correct |
6813 ms |
12216 KB |
Output is correct |
5 |
Correct |
6461 ms |
12120 KB |
Output is correct |
6 |
Runtime error |
16 ms |
33116 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
608 ms |
12048 KB |
Output is correct |
2 |
Correct |
9748 ms |
12352 KB |
Output is correct |
3 |
Correct |
6253 ms |
8684 KB |
Output is correct |
4 |
Correct |
6850 ms |
8680 KB |
Output is correct |
5 |
Correct |
6492 ms |
10648 KB |
Output is correct |
6 |
Runtime error |
20 ms |
32860 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |