#include<bits/stdc++.h>
using namespace std;
#include "wombats.h"
int h[5010][210], v[5010][210];
int f[210][210];
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 < r; i++) for(int j = 0; j + 1 < c; j++) h[i][j] = H[i][j];
for(int i = 0; i + 1 < r; i++) for(int j = 0; j < c; j++) v[i][j] = V[i][j];
// for(int i = 0; i < r; i++) {
// for(int j = 0; j + 1 < c; j++) cout << h[i][j] << " ";
// cout << endl;
// }
//
// for(int i = 0; i + 1 < r; i++) {
// for(int j = 0; j < c; j++) cout << v[i][j] << " ";
// cout << endl;
// }
}
void changeH(int P, int Q, int W) {
h[P][Q] = W;
/* ... */
}
void changeV(int P, int Q, int W) {
/* ... */
v[P][Q] = W;
}
void update (int l, int r) {
for(int i = 0; i < c; i++) for(int j = 0; j < c; j++) f[i][j] = (i == j ? 0 : 1e9);
for(int row = l; row <= r; row++) {
if (row != l) {
for(int i = 0; i < c; i++) for(int j = 0; j < c; j++) {
f[i][j] += v[row - 1][j];
}
}
for(int i = 0; i < c; i++) {
for(int j = 1; j < c; j++) f[i][j] = min(f[i][j], f[i][j - 1] + h[row][j - 1]);
for(int j = c - 2; j >= 0; j--) f[i][j] = min(f[i][j], f[i][j + 1] + h[row][j]);
}
}
}
int escape(int V1, int V2) {
update(0, r - 1);
return f[V1][V2];
}
#ifdef ngu
#define fail(s, x...) do { \
fprintf(stderr, s "\n", ## x); \
exit(1); \
} while(0)
static int H[5000][200];
static int V[5000][200];
int main() {
ofstream cout("task.out");
int R, C, E, P, Q, W, V1, V2, event, i, j;
int res;
FILE *f = fopen("task.inp", "r");
if (!f)
fail("Failed to open input file.");
res = fscanf(f, "%d%d", &R, &C);
for (i = 0; i < R; ++i)
for (j = 0; j < C-1; ++j)
res = fscanf(f, "%d", &H[i][j]);
for (i = 0; i < R-1; ++i)
for (j = 0; j < C; ++j)
res = fscanf(f, "%d", &V[i][j]);
init(R, C, H, V);
res = fscanf(f, "%d", &E);
for (i = 0; i < E; i++) {
res = fscanf(f, "%d", &event);
if (event == 1) {
res = fscanf(f, "%d%d%d", &P, &Q, &W);
changeH(P, Q, W);
} else if (event == 2) {
res = fscanf(f, "%d%d%d", &P, &Q, &W);
changeV(P, Q, W);
} else if (event == 3) {
res = fscanf(f, "%d%d", &V1, &V2);
printf("%d\n", escape(V1, V2));
} else
fail("Invalid event type.");
}
fclose(f);
return 0;
cout.close();
}
#endif // ngu
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;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
10892 KB |
Output is correct |
2 |
Correct |
9 ms |
10840 KB |
Output is correct |
3 |
Correct |
2922 ms |
13484 KB |
Output is correct |
4 |
Correct |
11 ms |
11096 KB |
Output is correct |
5 |
Correct |
9 ms |
10844 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
20 ms |
6748 KB |
Output is correct |
5 |
Correct |
18 ms |
6492 KB |
Output is correct |
6 |
Correct |
18 ms |
6492 KB |
Output is correct |
7 |
Correct |
19 ms |
6492 KB |
Output is correct |
8 |
Correct |
14 ms |
6612 KB |
Output is correct |
9 |
Correct |
17 ms |
6488 KB |
Output is correct |
10 |
Correct |
17 ms |
6616 KB |
Output is correct |
11 |
Correct |
8579 ms |
8808 KB |
Output is correct |
12 |
Correct |
19 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
697 ms |
6744 KB |
Output is correct |
2 |
Correct |
686 ms |
6720 KB |
Output is correct |
3 |
Correct |
704 ms |
6744 KB |
Output is correct |
4 |
Correct |
702 ms |
6748 KB |
Output is correct |
5 |
Correct |
690 ms |
6744 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2400 KB |
Output is correct |
9 |
Correct |
691 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
16716 KB |
Output is correct |
2 |
Correct |
54 ms |
16700 KB |
Output is correct |
3 |
Correct |
58 ms |
16732 KB |
Output is correct |
4 |
Correct |
5098 ms |
17916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
692 ms |
6748 KB |
Output is correct |
2 |
Correct |
676 ms |
6720 KB |
Output is correct |
3 |
Correct |
703 ms |
6748 KB |
Output is correct |
4 |
Correct |
702 ms |
6916 KB |
Output is correct |
5 |
Correct |
683 ms |
6744 KB |
Output is correct |
6 |
Correct |
56 ms |
16728 KB |
Output is correct |
7 |
Correct |
53 ms |
16712 KB |
Output is correct |
8 |
Correct |
61 ms |
16720 KB |
Output is correct |
9 |
Correct |
5012 ms |
18080 KB |
Output is correct |
10 |
Correct |
9 ms |
10844 KB |
Output is correct |
11 |
Correct |
9 ms |
10844 KB |
Output is correct |
12 |
Correct |
2786 ms |
13708 KB |
Output is correct |
13 |
Correct |
9 ms |
10840 KB |
Output is correct |
14 |
Correct |
9 ms |
10844 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
19 ms |
6492 KB |
Output is correct |
19 |
Correct |
19 ms |
6620 KB |
Output is correct |
20 |
Correct |
19 ms |
6492 KB |
Output is correct |
21 |
Correct |
18 ms |
6492 KB |
Output is correct |
22 |
Correct |
14 ms |
6608 KB |
Output is correct |
23 |
Correct |
17 ms |
6612 KB |
Output is correct |
24 |
Correct |
15 ms |
6492 KB |
Output is correct |
25 |
Correct |
8594 ms |
8812 KB |
Output is correct |
26 |
Correct |
21 ms |
6492 KB |
Output is correct |
27 |
Correct |
709 ms |
6744 KB |
Output is correct |
28 |
Execution timed out |
20094 ms |
20224 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
688 ms |
6748 KB |
Output is correct |
2 |
Correct |
678 ms |
6492 KB |
Output is correct |
3 |
Correct |
697 ms |
6748 KB |
Output is correct |
4 |
Correct |
702 ms |
6752 KB |
Output is correct |
5 |
Correct |
684 ms |
6744 KB |
Output is correct |
6 |
Correct |
54 ms |
16472 KB |
Output is correct |
7 |
Correct |
51 ms |
16476 KB |
Output is correct |
8 |
Correct |
53 ms |
16728 KB |
Output is correct |
9 |
Correct |
4789 ms |
17952 KB |
Output is correct |
10 |
Correct |
9 ms |
10844 KB |
Output is correct |
11 |
Correct |
9 ms |
10844 KB |
Output is correct |
12 |
Correct |
2971 ms |
13612 KB |
Output is correct |
13 |
Correct |
9 ms |
10844 KB |
Output is correct |
14 |
Correct |
10 ms |
10908 KB |
Output is correct |
15 |
Correct |
8695 ms |
26384 KB |
Output is correct |
16 |
Execution timed out |
20087 ms |
24428 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |