#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[5000][5000];
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<R+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 |
12376 KB |
Output is correct |
2 |
Correct |
6 ms |
12124 KB |
Output is correct |
3 |
Correct |
52 ms |
14788 KB |
Output is correct |
4 |
Correct |
6 ms |
12124 KB |
Output is correct |
5 |
Correct |
7 ms |
12124 KB |
Output is correct |
6 |
Correct |
5 ms |
8288 KB |
Output is correct |
7 |
Correct |
4 ms |
8192 KB |
Output is correct |
8 |
Correct |
5 ms |
8280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8284 KB |
Output is correct |
2 |
Correct |
4 ms |
8284 KB |
Output is correct |
3 |
Correct |
4 ms |
8284 KB |
Output is correct |
4 |
Correct |
6 ms |
8284 KB |
Output is correct |
5 |
Correct |
6 ms |
8400 KB |
Output is correct |
6 |
Correct |
5 ms |
8280 KB |
Output is correct |
7 |
Correct |
6 ms |
8284 KB |
Output is correct |
8 |
Correct |
5 ms |
8284 KB |
Output is correct |
9 |
Correct |
6 ms |
8388 KB |
Output is correct |
10 |
Correct |
6 ms |
8264 KB |
Output is correct |
11 |
Correct |
47 ms |
10588 KB |
Output is correct |
12 |
Correct |
6 ms |
8344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
593 ms |
9056 KB |
Output is correct |
2 |
Correct |
9376 ms |
9308 KB |
Output is correct |
3 |
Correct |
6114 ms |
9068 KB |
Output is correct |
4 |
Correct |
6709 ms |
9068 KB |
Output is correct |
5 |
Correct |
6451 ms |
9048 KB |
Output is correct |
6 |
Correct |
5 ms |
8284 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
5 ms |
8284 KB |
Output is correct |
9 |
Correct |
4030 ms |
9044 KB |
Output is correct |
10 |
Correct |
6 ms |
8280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
23 ms |
32860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
592 ms |
9044 KB |
Output is correct |
2 |
Correct |
9617 ms |
9412 KB |
Output is correct |
3 |
Correct |
6173 ms |
13592 KB |
Output is correct |
4 |
Correct |
6717 ms |
13400 KB |
Output is correct |
5 |
Correct |
6423 ms |
13588 KB |
Output is correct |
6 |
Runtime error |
17 ms |
35672 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
605 ms |
13464 KB |
Output is correct |
2 |
Correct |
9806 ms |
13732 KB |
Output is correct |
3 |
Correct |
6476 ms |
13588 KB |
Output is correct |
4 |
Correct |
7031 ms |
11868 KB |
Output is correct |
5 |
Correct |
6553 ms |
13588 KB |
Output is correct |
6 |
Runtime error |
20 ms |
33884 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |