#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];
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 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];
for(int i=0;i<R+5;i++)calc2(i);
}
void changeH(int P, int Q, int W) {
H[P][Q] = W;
for(int i=0;i<R+5;i++)calc2(i);
}
void changeV(int P, int Q, int W) {
sum -= V[P][Q];
sum += W;
V[P][Q] = W;
for(int i=0;i<R+5;i++)calc2(i);
}
int escape(int V1, int V2) {
if(C == 1){
return sum;
}
if(true){
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 |
Runtime error |
16 ms |
24664 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8284 KB |
Output is correct |
2 |
Correct |
4 ms |
8284 KB |
Output is correct |
3 |
Correct |
5 ms |
8284 KB |
Output is correct |
4 |
Correct |
5 ms |
8284 KB |
Output is correct |
5 |
Correct |
5 ms |
8284 KB |
Output is correct |
6 |
Correct |
5 ms |
8284 KB |
Output is correct |
7 |
Correct |
5 ms |
8284 KB |
Output is correct |
8 |
Correct |
6 ms |
8284 KB |
Output is correct |
9 |
Correct |
5 ms |
8284 KB |
Output is correct |
10 |
Correct |
9 ms |
8284 KB |
Output is correct |
11 |
Correct |
55 ms |
10596 KB |
Output is correct |
12 |
Correct |
5 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10268 ms |
8980 KB |
Output is correct |
2 |
Correct |
16170 ms |
9200 KB |
Output is correct |
3 |
Correct |
10208 ms |
9068 KB |
Output is correct |
4 |
Correct |
10270 ms |
9072 KB |
Output is correct |
5 |
Correct |
10166 ms |
9048 KB |
Output is correct |
6 |
Correct |
6 ms |
8284 KB |
Output is correct |
7 |
Correct |
4 ms |
8304 KB |
Output is correct |
8 |
Correct |
4 ms |
8280 KB |
Output is correct |
9 |
Execution timed out |
20092 ms |
9044 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
22 ms |
32856 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10028 ms |
9060 KB |
Output is correct |
2 |
Correct |
16192 ms |
9196 KB |
Output is correct |
3 |
Correct |
10155 ms |
8924 KB |
Output is correct |
4 |
Correct |
10109 ms |
9044 KB |
Output is correct |
5 |
Correct |
10208 ms |
9064 KB |
Output is correct |
6 |
Runtime error |
24 ms |
32860 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10116 ms |
9056 KB |
Output is correct |
2 |
Correct |
16239 ms |
9192 KB |
Output is correct |
3 |
Correct |
10245 ms |
9068 KB |
Output is correct |
4 |
Correct |
10219 ms |
9044 KB |
Output is correct |
5 |
Correct |
10161 ms |
9076 KB |
Output is correct |
6 |
Runtime error |
20 ms |
32784 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |