#include "wombats.h"
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> h , v;
int r , c;
int xx[3] = {1 , 0 , 0};
int yy[3] = {0 , -1 , 1};
vector<vector<int>> all;
int escape_(int V1, int V2) {
priority_queue<pair<int ,pair<int ,int>> ,vector<pair<int ,pair<int,int>>>, greater<pair<int ,pair<int, int>>>> pq;
pq.push({0 , {0 , V1}});
vector<vector<bool>> vis(r , vector<bool>(c));
vector<vector<int>> dist(r , vector<int>(c , 2e9));
dist[0][V1] = 0;
while(!pq.empty())
{
auto [d , p] = pq.top();
auto [i , j] = p;
pq.pop();
if(vis[i][j])
continue;
vis[i][j] = 1;
for(int k = 0 ; k < 3 ; k++)
{
int ni = i + xx[k] , nj = j + yy[k];
if(ni >= 0 && nj >= 0 && ni < r && nj < c)
{
int cost = 0;
if(xx[k] == 1)
cost = v[i][j];
if(yy[k] == 1)
cost = h[i][j];
if(yy[k] == -1)
cost = h[i][j - 1];
if(dist[ni][nj] > dist[i][j] + cost)
{
dist[ni][nj] = dist[i][j] + cost;
pq.push({dist[ni][nj] , {ni , nj}});
}
}
}
}
return dist[r - 1][V2];
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
r = R;
c = C;
all.assign(c , vector<int>(c));
h.assign(R , vector<int>(C));
v = h;
for(int i = 0 ; i < R ; i++)
{
for(int j = 0; j < C - 1 ; j++)
{
h[i][j] = H[i][j];
}
}
for(int i = 0 ; i < R-1 ; i++)
{
for(int j = 0; j < C ; j++)
{
v[i][j] = V[i][j];
}
}
for(int i = 0; i < c ; i++)
{
for(int j = 0 ; j < c ; j++)
{
all[i][j] = escape_(i , j);
}
}
}
void changeH(int P, int Q, int W) {
h[P][Q] = W;
for(int i = 0; i < c ; i++)
{
for(int j = 0 ; j < c ; j++)
{
all[i][j] = escape_(i , j);
}
}
}
void changeV(int P, int Q, int W) {
v[P][Q] = W;
for(int i = 0; i < c ; i++)
{
for(int j = 0 ; j < c ; j++)
{
all[i][j] = escape_(i , j);
}
}
}
int escape(int i , int j)
{
return all[i][j];
}
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 |
185 ms |
5500 KB |
Output is correct |
2 |
Correct |
230 ms |
5532 KB |
Output is correct |
3 |
Correct |
244 ms |
8296 KB |
Output is correct |
4 |
Correct |
182 ms |
5496 KB |
Output is correct |
5 |
Correct |
193 ms |
5732 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
8 ms |
500 KB |
Output is correct |
5 |
Correct |
6 ms |
492 KB |
Output is correct |
6 |
Correct |
5 ms |
348 KB |
Output is correct |
7 |
Correct |
10 ms |
348 KB |
Output is correct |
8 |
Correct |
6 ms |
500 KB |
Output is correct |
9 |
Correct |
7 ms |
344 KB |
Output is correct |
10 |
Correct |
6 ms |
500 KB |
Output is correct |
11 |
Correct |
54 ms |
2700 KB |
Output is correct |
12 |
Correct |
10 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
20050 ms |
860 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1210 ms |
9608 KB |
Output is correct |
2 |
Correct |
2317 ms |
9368 KB |
Output is correct |
3 |
Correct |
1322 ms |
9484 KB |
Output is correct |
4 |
Correct |
1269 ms |
10628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
20021 ms |
856 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
20056 ms |
860 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |