// ~ 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][maxnR][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) {
h[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 |
22 ms |
12244 KB |
Output is correct |
2 |
Incorrect |
24 ms |
12284 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 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 |
2040 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
273 ms |
884 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
16248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
262 ms |
1012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
261 ms |
804 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |