This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "wombats.h"
using namespace std;
int r,c,h[5001][201],v[5001][201];
int dp[201][201][201];
bool subt2;
bool subt3;
void init(int R,int C,int H[5000][200],int V[5000][200])
{
r=R;
c=C;
if(r<=100&&c<=100)
subt3=1;
else subt2=1;
if(subt2)
{
for(int i=0; i<R; i++)
{
for(int j=0; j<C; j++)
{
h[i][j]=H[i][j];
v[i][j]=V[i][j];
}
}
//cout<<r<<" "<<c<<endl;
for(int i=0; i<r; i++)
{
for(int j=0; j<c; j++)
{
for(int k=0; k<c; k++)
{
dp[i][j][k]=1e9;
}
dp[0][j][j]=0;
}
}
for(int k=0; k<c; k++)
for(int i=0; i<r; i++)
{
for(int j=c-1; j>=0; j--)
{
//cout<<dp[i][j][k]<<endl;
if(i>0)dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k]+v[i-1][j]);
if(j<c-1)dp[i][j][k]=min(dp[i][j][k],dp[i][j+1][k]+h[i][j]);
}
for(int j=0; j<c; j++)
{
//cout<<dp[i][j][k]<<endl;
if(i>0)dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k]+v[i-1][j]);
if(j>0)dp[i][j][k]=min(dp[i][j][k],dp[i][j-1][k]+h[i][j-1]);
//cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
}
}
}
}
void changeH(int x,int y,int w)
{
h[x][y]=w;
}
void changeV(int x,int y,int w)
{
v[x][y]=w;
}
int escape(int x,int y)
{
if(subt2)return dp[r-1][y][x];
if(subt3)
{
int k=x;
for(int i=0;i<r;i++)
{
for(int j=c-1;j>=0;j--)
{
dp[i][j][k]=1e9;
}
}
dp[0][k][k]=0;
for(int i=0; i<r; i++)
{
for(int j=c-1; j>=0; j--)
{
//cout<<dp[i][j][k]<<endl;
if(i>0)dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k]+v[i-1][j]);
if(j<c-1)dp[i][j][k]=min(dp[i][j][k],dp[i][j+1][k]+h[i][j]);
}
for(int j=0; j<c; j++)
{
//cout<<dp[i][j][k]<<endl;
if(i>0)dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k]+v[i-1][j]);
if(j>0)dp[i][j][k]=min(dp[i][j][k],dp[i][j-1][k]+h[i][j-1]);
//cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
}
}
return dp[r-1][y][x];
}
}
Compilation message (stderr)
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
15 | int res;
| ^~~
wombats.cpp: In function 'int escape(int, int)':
wombats.cpp:103:1: warning: control reaches end of non-void function [-Wreturn-type]
103 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |