#include <queue>
// #include "wombats.h"
#include <algorithm>
using namespace std;
int costy[5000][200],costx[5000][200];
int r,c;
void init(int R, int C, int H[5000][200], int V[5000][200])
{
r=R;
c=C;
for (int i=0;i<C-1;i++)
for (int j=0;j<R;j++)
costx[j][i]=H[j][i];
for (int i=0;i<R-1;i++)
for (int j=0;j<C;j++)
costy[i][j]=V[i][j];
}
int dist[5000][200]={};
bool check(int i,int j)
{
if (i>=0&&i<r&&j>=0&&j<c)
return 1;
return 0;
}
void bfs(int i,int j)
{
queue<pair<int,int>>Q;
Q.push({i,j});
dist[i][j]=0;
while (Q.size())
{
int x,y;
tie(x,y)=Q.front();
Q.pop();
if (check(x+1,y))
if (dist[x+1][y]>dist[x][y]+costy[x][y])
{
dist[x+1][y]=dist[x][y]+costy[x][y];
Q.push({x+1,y});
}
if (check(x,y+1))
if (dist[x][y+1]>dist[x][y]+costx[x][y])
{
dist[x][y+1]=dist[x][y]+costx[x][y];
Q.push({x,y+1});
}
if (check(x,y-1))
if (dist[x][y-1]>dist[x][y]+costx[x][y-1])
{
dist[x][y-1]=dist[x][y]+costx[x][y-1];
Q.push({x,y-1});
}
}
}
void changeH(int P, int Q, int W)
{
costx[P][Q]=W;
}
void changeV(int P, int Q, int W)
{
costy[P][Q]=W;
}
int escape(int V1, int V2)
{
if (c==1)
{
int ans=0;
for (int i=min(V1,V2);i<=max(V1,V2);i++)
ans+=costx[0][i];
ans-=costx[0][V2];
return ans;
}
for (int i=0;i<r;i++)
for (int j=0;j<c;j++)
dist[i][j]=1e9+10;
bfs(0,V1);
return dist[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;
| ^~~
/usr/bin/ld: /tmp/ccvpnE2T.o: in function `main':
grader.c:(.text.startup+0x129): undefined reference to `init'
/usr/bin/ld: grader.c:(.text.startup+0x194): undefined reference to `escape'
/usr/bin/ld: grader.c:(.text.startup+0x203): undefined reference to `changeH'
/usr/bin/ld: grader.c:(.text.startup+0x26d): undefined reference to `changeV'
collect2: error: ld returned 1 exit status