This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//In the name of God
#include <bits/stdc++.h>
#include "wombats.h"
using namespace std;
typedef int ll;
typedef pair<ll, ll> pll;
const ll maxn = 5010;
const ll maxm = 210;
const ll mod = 1e9 + 7;
const ll inf = 1e9;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
ll r, c;
ll h[maxn][maxm], v[maxn][maxm];
ll dis[maxm][maxm], dl[maxm], dr[maxm];
void solve(){
for(ll i = 0; i < c; i++){
fill(dis[i], dis[i] + c, inf);
dis[i][i] = 0;
for(ll o = 0; o < r; o++){
for(ll j = 0; j < c; j++){
dl[j] = dis[i][j];
if(j) dl[j] = min(dl[j], dl[j - 1] + h[o][j - 1]);
}
for(ll j = c; j--;){
dr[j] = dis[i][j];
if(j + 1 < c) dr[j] = min(dr[j], dr[j + 1] + h[o][j]);
}
for(ll j = 0; j < c; j++){
dis[i][j] = min(dl[j], dr[j]) + v[o][j];
}
}
}
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
r = R;
c = C;
for(ll i = 0; i < r; i++){
for(ll j = 0; j < c - 1; j++){
h[i][j] = H[i][j];
}
}
for(ll i = 0; i < r - 1; i++){
for(ll j = 0; j < c; j++){
v[i][j] = V[i][j];
}
}
solve();
}
void changeH(int P, int Q, int W) {
h[P][Q] = W;
solve();
}
void changeV(int P, int Q, int W) {
v[P][Q] = W;
solve();
}
int escape(int V1, int V2) {
return dis[V1][V2];
}
/*int main(){
fast_io;
cin >> r >> c;
for(ll i = 0; i < r; i++){
for(ll j = 0; j < c - 1; j++){
cin >> h[i][j];
}
}
for(ll i = 0; i < r - 1; i++){
for(ll j = 0; j < c; j++){
cin >> v[i][j];
}
}
solve();
cout << escape(2, 1) << "\n";
cout << escape(3, 3) << "\n";
changeV(0,0,5);
changeH(1,1,6);
cout << escape(2, 1) << "\n";
return 0;
}*/
Compilation message (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |