#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;
int tot;
void init(int R,int C,int H[5000][200],int V[5000][200])
{
r=R;
c=C;
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];
tot+=h[i][j];
tot+=v[i][j];
}
}
if(r<=100&&c<=100||c==2)
subt3=1;
else if(c!=1)subt2=1;
if(subt2)
{
//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)
{
tot-=h[x][y];
h[x][y]=w;
tot+=w;
}
void changeV(int x,int y,int w)
{
tot-=v[x][y];
v[x][y]=w;
tot+=w;
}
int escape(int x,int y)
{
if(c==1)return tot;
if(subt2)return dp[r-1][y][x];
//cout<<x<<" --- "<<y<<endl;
int k=x;
for(int i=0; i<r; i++)
{
for(int j=0; j<c; 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
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 'void init(int, int, int (*)[200], int (*)[200])':
wombats.cpp:24:14: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
24 | if(r<=100&&c<=100||c==2)
| ~~~~~~^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12892 KB |
Output is correct |
2 |
Correct |
2 ms |
12892 KB |
Output is correct |
3 |
Correct |
63 ms |
15316 KB |
Output is correct |
4 |
Correct |
2 ms |
12892 KB |
Output is correct |
5 |
Correct |
2 ms |
12892 KB |
Output is correct |
6 |
Correct |
1 ms |
4540 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
3 ms |
10680 KB |
Output is correct |
5 |
Correct |
3 ms |
10592 KB |
Output is correct |
6 |
Correct |
3 ms |
10588 KB |
Output is correct |
7 |
Correct |
3 ms |
10588 KB |
Output is correct |
8 |
Correct |
3 ms |
10588 KB |
Output is correct |
9 |
Correct |
3 ms |
10588 KB |
Output is correct |
10 |
Correct |
3 ms |
10584 KB |
Output is correct |
11 |
Correct |
645 ms |
12888 KB |
Output is correct |
12 |
Correct |
3 ms |
10584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23708 KB |
Output is correct |
2 |
Correct |
13 ms |
23388 KB |
Output is correct |
3 |
Correct |
13 ms |
23388 KB |
Output is correct |
4 |
Correct |
17 ms |
23512 KB |
Output is correct |
5 |
Correct |
14 ms |
23648 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
14 ms |
23388 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
58 ms |
96696 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23640 KB |
Output is correct |
2 |
Correct |
14 ms |
23488 KB |
Output is correct |
3 |
Correct |
14 ms |
23388 KB |
Output is correct |
4 |
Correct |
14 ms |
23388 KB |
Output is correct |
5 |
Correct |
16 ms |
23492 KB |
Output is correct |
6 |
Runtime error |
60 ms |
96848 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23504 KB |
Output is correct |
2 |
Correct |
13 ms |
23388 KB |
Output is correct |
3 |
Correct |
13 ms |
23476 KB |
Output is correct |
4 |
Correct |
15 ms |
23384 KB |
Output is correct |
5 |
Correct |
13 ms |
23456 KB |
Output is correct |
6 |
Runtime error |
50 ms |
96852 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |