#include "wombats.h"
#include <queue>
#include <algorithm>
using namespace std;
int n,m;
int h[5000][200];
int v[5000][200];
int dp[5000][200];
void init(int R, int C, int H[5000][200], int V[5000][200]) {
n = R;
m = 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];
}
}
}
void changeH(int P, int Q, int W) {
h[P][Q] = W;
}
void changeV(int P, int Q, int W) {
v[P][Q] = W;
}
int escape(int V1, int V2) {
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
dp[i][j] = 1 << 28;
}
}
dp[0][V1] = 0;
for(int i = V1 - 1;i >= 0;i--){
dp[0][i] = dp[0][i + 1] + h[0][i];
}
for(int i = V1 + 1;i < m;i++){
dp[0][i] = dp[0][i - 1] + h[0][i - 1];
}
for(int i = 1;i < n;i++){
queue< pair<int,int> > q;
for(int j = 0;j < m;j++){
dp[i][j] = dp[i - 1][j] + v[i - 1][j];
q.push({j,dp[i][j]});
}
while(!q.empty()){
int x = q.front().first;
int cost = q.front().second;
q.pop();
if(x > 0 && dp[i][x - 1] > dp[i][x] + h[i][x - 1]){
dp[i][x - 1] = dp[i][x] + h[i][x - 1];
q.push({x - 1,dp[i][x - 1]});
}
if(x + 1 < m && dp[i][x + 1] > dp[i][x] + h[i][x]){
dp[i][x + 1] = dp[i][x] + h[i][x];
q.push({x + 1,dp[i][x + 1]});
}
}
}
return dp[n - 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]
int res;
^~~
wombats.cpp: In function 'int escape(int, int)':
wombats.cpp:59:17: warning: unused variable 'cost' [-Wunused-variable]
int cost = q.front().second;
^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
305 ms |
15996 KB |
Output is correct |
2 |
Correct |
310 ms |
16120 KB |
Output is correct |
3 |
Execution timed out |
20039 ms |
16916 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
7 ms |
512 KB |
Output is correct |
8 |
Correct |
7 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
6 ms |
512 KB |
Output is correct |
11 |
Correct |
1988 ms |
2804 KB |
Output is correct |
12 |
Correct |
8 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
768 KB |
Output is correct |
2 |
Correct |
29 ms |
768 KB |
Output is correct |
3 |
Correct |
31 ms |
848 KB |
Output is correct |
4 |
Correct |
37 ms |
896 KB |
Output is correct |
5 |
Correct |
34 ms |
768 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
36 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
961 ms |
19980 KB |
Output is correct |
2 |
Correct |
768 ms |
20088 KB |
Output is correct |
3 |
Correct |
758 ms |
20088 KB |
Output is correct |
4 |
Execution timed out |
20089 ms |
20712 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
848 KB |
Output is correct |
2 |
Correct |
27 ms |
768 KB |
Output is correct |
3 |
Correct |
36 ms |
768 KB |
Output is correct |
4 |
Correct |
32 ms |
888 KB |
Output is correct |
5 |
Correct |
32 ms |
888 KB |
Output is correct |
6 |
Correct |
836 ms |
19988 KB |
Output is correct |
7 |
Correct |
744 ms |
19968 KB |
Output is correct |
8 |
Correct |
853 ms |
20216 KB |
Output is correct |
9 |
Execution timed out |
20025 ms |
20700 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
888 KB |
Output is correct |
2 |
Correct |
30 ms |
768 KB |
Output is correct |
3 |
Correct |
32 ms |
852 KB |
Output is correct |
4 |
Correct |
35 ms |
768 KB |
Output is correct |
5 |
Correct |
38 ms |
856 KB |
Output is correct |
6 |
Correct |
875 ms |
19984 KB |
Output is correct |
7 |
Correct |
858 ms |
19980 KB |
Output is correct |
8 |
Correct |
846 ms |
20088 KB |
Output is correct |
9 |
Execution timed out |
20081 ms |
20704 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |