// ~ Be Name Khoda ~ //
#include "wombats.h"
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const int maxn = 1e6 + 10;
const int maxn5 = 5e5 + 10;
const int maxnC = 205;
const int maxnR = 5e3 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9;
int n, m;
int dp[2][maxnC][maxnC];
int v[maxnR][maxnC], h[maxnR][maxnC];
inline void build(){
for(int i = 0; i < m; i++) for(int j = 0; j < m; j++)
dp[1][i][j] = inf;
for(int i = 0; i < m; i++)
dp[1][i][i] = 0;
for(int j = 0; j < n; j++) for(int x = 0; x < m; x++){
int mn = inf;
for(int i = 0; i < m; i++){
dp[j & 1][x][i] = min(mn, dp[(j + 1) & 1][x][i] + (j ? v[j - 1][i] : 0));
mn = dp[j & 1][x][i] + h[j][i];
}
mn = inf;
for(int i = m - 1; i >= 0; i--){
dp[j & 1][x][i] = min(mn, dp[j & 1][x][i]);
if(i)
mn = dp[j & 1][x][i] + h[j][i - 1];
//cout << "check " << j << ' ' << x << ' ' << i << ' ' << dp[j & 1][x][i] << ' ' << mn << endl;
}
}
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
n = R;
m = C;
for(int i = 0; i < n; i++) for(int j = 0; j < m; j++){
h[i][j] = H[i][j];
v[i][j] = V[i][j];
}
build();
}
void changeH(int P, int Q, int W) {
h[P][Q] = W;
build();
}
void changeV(int P, int Q, int W) {
v[P][Q] = W;
build();
}
int escape(int v1, int v2){
return dp[(n - 1) & 1][v1][v2];
}
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 |
24 ms |
12244 KB |
Output is correct |
2 |
Correct |
24 ms |
12244 KB |
Output is correct |
3 |
Correct |
88 ms |
14456 KB |
Output is correct |
4 |
Correct |
23 ms |
12244 KB |
Output is correct |
5 |
Correct |
22 ms |
12244 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
224 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
54 ms |
1344 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
265 ms |
724 KB |
Output is correct |
2 |
Correct |
255 ms |
860 KB |
Output is correct |
3 |
Correct |
263 ms |
852 KB |
Output is correct |
4 |
Correct |
263 ms |
876 KB |
Output is correct |
5 |
Correct |
260 ms |
884 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1293 ms |
872 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
16168 KB |
Output is correct |
2 |
Correct |
34 ms |
16204 KB |
Output is correct |
3 |
Correct |
38 ms |
16228 KB |
Output is correct |
4 |
Correct |
89 ms |
17552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
260 ms |
792 KB |
Output is correct |
2 |
Correct |
258 ms |
876 KB |
Output is correct |
3 |
Correct |
268 ms |
872 KB |
Output is correct |
4 |
Correct |
264 ms |
872 KB |
Output is correct |
5 |
Correct |
257 ms |
836 KB |
Output is correct |
6 |
Correct |
42 ms |
16232 KB |
Output is correct |
7 |
Correct |
35 ms |
16212 KB |
Output is correct |
8 |
Correct |
35 ms |
16212 KB |
Output is correct |
9 |
Correct |
63 ms |
17496 KB |
Output is correct |
10 |
Correct |
23 ms |
12244 KB |
Output is correct |
11 |
Correct |
23 ms |
12244 KB |
Output is correct |
12 |
Correct |
83 ms |
14476 KB |
Output is correct |
13 |
Correct |
22 ms |
12244 KB |
Output is correct |
14 |
Correct |
22 ms |
12272 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
304 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
436 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
392 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
55 ms |
1940 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1308 ms |
872 KB |
Output is correct |
28 |
Execution timed out |
20024 ms |
16972 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
261 ms |
724 KB |
Output is correct |
2 |
Correct |
263 ms |
796 KB |
Output is correct |
3 |
Correct |
264 ms |
844 KB |
Output is correct |
4 |
Correct |
271 ms |
812 KB |
Output is correct |
5 |
Correct |
258 ms |
792 KB |
Output is correct |
6 |
Correct |
34 ms |
16084 KB |
Output is correct |
7 |
Correct |
44 ms |
16148 KB |
Output is correct |
8 |
Correct |
36 ms |
16168 KB |
Output is correct |
9 |
Correct |
62 ms |
16844 KB |
Output is correct |
10 |
Correct |
23 ms |
12244 KB |
Output is correct |
11 |
Correct |
22 ms |
12244 KB |
Output is correct |
12 |
Correct |
75 ms |
13792 KB |
Output is correct |
13 |
Correct |
26 ms |
12368 KB |
Output is correct |
14 |
Correct |
22 ms |
12260 KB |
Output is correct |
15 |
Correct |
2768 ms |
16468 KB |
Output is correct |
16 |
Execution timed out |
20035 ms |
16596 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |