This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
const int nx=5e3+5, cx=1e2+5;
int r, c, ver[nx][cx], qs[nx][cx], dp[nx][cx];
int dist(int row, int a, int b)
{
if (b>=a) return ver[row][a]+qs[row][b]-qs[row][a];
else return ver[row][a]+qs[row][a]-qs[row][b];
}
struct segtree
{
struct matrix
{
int mat[cx][cx];
void build(int row)
{
for (int i=0; i<c; i++) for (int j=0; j<c; j++) mat[i][j]=dist(row, j, i);
/*
cout<<"build "<<row<<'\n';
for (int i=0; i<c; i++){
for (int j=0; j<c; j++) cout<<mat[i][j]<<' ';
cout<<'\n';}
*/
}
} d[4*nx];
void merge(int l, int r, int idx)
{
for (int i=0; i<c; i++) for (int j=0; j<c; j++) d[idx].mat[i][j]=1e9;
for (int i=0; i<c; i++) for (int j=0; j<c; j++) for (int k=0; k<c; k++) d[idx].mat[i][j]=min(d[idx].mat[i][j], d[2*idx+1].mat[i][k]+d[2*idx].mat[k][j]);
}
void build(int l, int r, int i)
{
if (l==r) return d[i].build(l), void();
int md=(l+r)/2;
build(l, md, 2*i);
build(md+1, r, 2*i+1);
merge(l, r, i);
}
void update(int l, int r, int i, int idx)
{
if (idx<l||r<idx) return;
if (l==r) return d[i].build(idx), void();
int md=(l+r)/2;
update(l, md, 2*i, idx);
update(md+1, r, 2*i+1, idx);
merge(l, r, i);
}
} s;
void init(int R, int C, int H[5000][200], int V[5000][200]) {
r=R, c=C;
for (int i=0; i<R-1; i++) for (int j=0; j<C; j++) ver[i+1][j]=V[i][j];
for (int i=0; i<R; i++) for (int j=0; j<C-1; j++) qs[i][j+1]=H[i][j]+qs[i][j];
s.build(1, r-1, 1);
/*
for (int i=0; i<c; i++)
{
cout<<"mat ";
for (int j=0; j<c; j++) cout<<s.d[1].mat[i][j]<<' ';
cout<<'\n';
}
*/
}
void changeH(int P, int Q, int W) {
int lst=qs[P][Q+1]-qs[P][Q];
int delta=W-lst;
for (int i=Q+1; i<c; i++) qs[P][i]+=delta;
if (P>0) s.update(1, r-1, 1, P);
}
void changeV(int P, int Q, int W) {
ver[P+1][Q]=W;
s.update(1, r-1, 1, P+1);
}
int escape(int V1, int V2) {
vector<int> tmp;
int res=1e9;
for (int i=0; i<c; i++) res=min(res, s.d[1].mat[V2][i]+dist(0, V1, i));
return res;
}
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... |