#include "wombats.h"
#include <bits/stdc++.h>
#define F first
#define S seoncd
typedef long long ll;
using namespace std;
int r,c,sum;
int h[5010][210];
int v[5010][210];
int dp[110][110][3];
int dp1[5010][3][3][5];
int en;
int Solve (int x,int y,int d){
if (x==r-1&&y==en){
return 0;
}
int &res=dp[x][y][d];
if (res!=-1)return res;
res=1000000000;
if (y>0&&d!=2){
res=min(res,Solve(x,y-1,1)+h[x][y-1]);
}
if (y<c-1&&d!=1){
res=min(res,Solve(x,y+1,2)+h[x][y]);
}
if (x<r-1)
res=min(res,Solve(x+1,y,0)+v[x][y]);
return res;
}
int Solve1 (int x,int y,int d,int dpnum){
if (x==r-1&&y==en){
return 0;
}
int &res=dp1[x][y][d][dpnum];
if (res!=-1)return res;
res=1000000000;
if (y>0&&d!=2){
res=min(res,Solve1(x,y-1,1,dpnum)+h[x][y-1]);
}
if (y<c-1&&d!=1){
res=min(res,Solve1(x,y+1,2,dpnum)+h[x][y]);
}
if (x<r-1)
res=min(res,Solve1(x+1,y,0,dpnum)+v[x][y]);
return res;
}
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 l=0;l<c-1;l++){
h[i][l]=H[i][l];
}
}
for (int i=0;i<r-1;i++){
for (int l=0;l<c;l++){
v[i][l]=V[i][l];
sum+=v[i][l];
}
}
if (c==2){
memset(dp1,-1,sizeof dp1);
en=0;
Solve1(0,0,0,0);
Solve1(0,1,0,1);
en=1;
Solve1(0,0,0,2);
Solve1(0,1,0,3);
}
}
void changeH(int P, int Q, int W) {
h[P][Q]=W;
if (c==2){
memset(dp1,-1,sizeof dp1);
en=0;
Solve1(0,0,0,0);
Solve1(0,1,0,1);
en=1;
Solve1(0,0,0,2);
Solve1(0,1,0,3);
}
}
void changeV(int P, int Q, int W) {
sum-=v[P][Q];
v[P][Q]=W;
sum+=v[P][Q];
if (c==2){
memset(dp1,-1,sizeof dp1);
en=0;
Solve1(0,0,0,0);
Solve1(0,1,0,1);
en=1;
Solve1(0,0,0,2);
Solve1(0,1,0,3);
}
}
int escape(int V1, int V2) {
if (c==1){
return sum;
}
if (c==2){
en=V2;
return Solve1(0,V1,0,en*2+V1);
}
memset(dp,-1,sizeof dp);
en=V2;
return Solve(0,V1,0);
}
/*
3 4
0 2 5
7 1 1
0 4 0
0 0 0 2
0 3 4 7
5
3 2 1
3 3 3
2 0 0 5
1 1 1 6
3 2 1
*/
Compilation message
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
int res;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
8312 KB |
Output is correct |
2 |
Correct |
12 ms |
8444 KB |
Output is correct |
3 |
Correct |
97 ms |
9996 KB |
Output is correct |
4 |
Correct |
9 ms |
9996 KB |
Output is correct |
5 |
Correct |
9 ms |
9996 KB |
Output is correct |
6 |
Correct |
2 ms |
9996 KB |
Output is correct |
7 |
Correct |
3 ms |
9996 KB |
Output is correct |
8 |
Correct |
3 ms |
9996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
9996 KB |
Output is correct |
2 |
Correct |
2 ms |
9996 KB |
Output is correct |
3 |
Correct |
4 ms |
9996 KB |
Output is correct |
4 |
Correct |
16 ms |
9996 KB |
Output is correct |
5 |
Correct |
15 ms |
9996 KB |
Output is correct |
6 |
Correct |
20 ms |
9996 KB |
Output is correct |
7 |
Correct |
16 ms |
9996 KB |
Output is correct |
8 |
Correct |
14 ms |
9996 KB |
Output is correct |
9 |
Correct |
19 ms |
9996 KB |
Output is correct |
10 |
Correct |
15 ms |
9996 KB |
Output is correct |
11 |
Correct |
5722 ms |
9996 KB |
Output is correct |
12 |
Correct |
17 ms |
9996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
9996 KB |
Output is correct |
2 |
Correct |
64 ms |
9996 KB |
Output is correct |
3 |
Correct |
70 ms |
9996 KB |
Output is correct |
4 |
Correct |
72 ms |
9996 KB |
Output is correct |
5 |
Correct |
76 ms |
9996 KB |
Output is correct |
6 |
Correct |
2 ms |
9996 KB |
Output is correct |
7 |
Correct |
3 ms |
9996 KB |
Output is correct |
8 |
Correct |
2 ms |
9996 KB |
Output is correct |
9 |
Correct |
76 ms |
9996 KB |
Output is correct |
10 |
Correct |
3 ms |
9996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1243 ms |
18468 KB |
Output is correct |
2 |
Correct |
1336 ms |
18472 KB |
Output is correct |
3 |
Correct |
1088 ms |
18520 KB |
Output is correct |
4 |
Correct |
1084 ms |
19500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
19500 KB |
Output is correct |
2 |
Correct |
61 ms |
19500 KB |
Output is correct |
3 |
Correct |
65 ms |
19500 KB |
Output is correct |
4 |
Correct |
64 ms |
19500 KB |
Output is correct |
5 |
Correct |
68 ms |
19500 KB |
Output is correct |
6 |
Correct |
1186 ms |
19500 KB |
Output is correct |
7 |
Correct |
1159 ms |
19500 KB |
Output is correct |
8 |
Correct |
1130 ms |
19500 KB |
Output is correct |
9 |
Correct |
1422 ms |
19652 KB |
Output is correct |
10 |
Correct |
12 ms |
19652 KB |
Output is correct |
11 |
Correct |
11 ms |
19652 KB |
Output is correct |
12 |
Correct |
94 ms |
19652 KB |
Output is correct |
13 |
Correct |
11 ms |
19652 KB |
Output is correct |
14 |
Correct |
11 ms |
19652 KB |
Output is correct |
15 |
Correct |
3 ms |
19652 KB |
Output is correct |
16 |
Correct |
3 ms |
19652 KB |
Output is correct |
17 |
Correct |
3 ms |
19652 KB |
Output is correct |
18 |
Correct |
14 ms |
19652 KB |
Output is correct |
19 |
Correct |
16 ms |
19652 KB |
Output is correct |
20 |
Correct |
15 ms |
19652 KB |
Output is correct |
21 |
Correct |
15 ms |
19652 KB |
Output is correct |
22 |
Correct |
16 ms |
19652 KB |
Output is correct |
23 |
Correct |
14 ms |
19652 KB |
Output is correct |
24 |
Correct |
13 ms |
19652 KB |
Output is correct |
25 |
Correct |
6483 ms |
19652 KB |
Output is correct |
26 |
Correct |
19 ms |
19652 KB |
Output is correct |
27 |
Correct |
96 ms |
19652 KB |
Output is correct |
28 |
Execution timed out |
20041 ms |
25304 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
25304 KB |
Output is correct |
2 |
Correct |
66 ms |
25304 KB |
Output is correct |
3 |
Correct |
84 ms |
25304 KB |
Output is correct |
4 |
Correct |
97 ms |
25304 KB |
Output is correct |
5 |
Correct |
78 ms |
25304 KB |
Output is correct |
6 |
Correct |
1175 ms |
25660 KB |
Output is correct |
7 |
Correct |
1238 ms |
25664 KB |
Output is correct |
8 |
Correct |
1283 ms |
25704 KB |
Output is correct |
9 |
Correct |
1444 ms |
26680 KB |
Output is correct |
10 |
Correct |
11 ms |
26680 KB |
Output is correct |
11 |
Correct |
11 ms |
26680 KB |
Output is correct |
12 |
Correct |
116 ms |
26680 KB |
Output is correct |
13 |
Correct |
13 ms |
26680 KB |
Output is correct |
14 |
Correct |
12 ms |
26680 KB |
Output is correct |
15 |
Incorrect |
267 ms |
37132 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |