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;
using ll = long long;
const int N = 5000;
const int M = 100;
int rc[N][M]; // cost from (i, j) -> (i+1, j)
int cc[N][M]; // cost from (i, j) -> (i, j+1)
int n, m;
struct A {
vector<vector<int>> dis;
int r;
void init() {
dis.assign(m, vector<int>(m, 1e9));
}
A operator + (const A& o) const {
A res;
res.init();
for (int i = 0;i < m;i++) {
for (int j = 0;j < m;j++) {
for (int k = 0;k < m;k++) {
res.dis[i][j] = min(res.dis[i][j],
dis[i][k] + rc[r][k] + o.dis[k][j]);
}
}
}
res.r = o.r;
return res;
}
} now;
A cal(int r) {
A now;
vector<int> sum(m);
sum[0] = 0;
for (int i = 1;i < m;i++) {
sum[i] = sum[i - 1] + cc[r][i - 1];
}
for (int i = 0;i < m;i++) {
for (int j = i;j < m;j++) {
now.dis[i][j] = now.dis[j][i] = sum[j] - sum[i];
}
}
now.r = r;
return now;
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
n = R, m = C;
for (int i = 0;i < n - 1;i++) {
for (int j = 0;j < m;j++) {
rc[i][j] = V[i][j];
}
}
for (int i = 0;i < n;i++) {
for (int j = 0;j < m - 1;j++) {
cc[i][j] = H[i][j];
}
}
now = cal(0);
for (int i = 1;i < n;i++) now = now + cal(i);
}
void changeH(int P, int Q, int W) {
cc[P][Q] = W;
now = cal(0);
for (int i = 1;i < n;i++) {
now = now + cal(i);
}
}
void changeV(int P, int Q, int W) {
rc[P][Q] = W;
now = cal(0);
for (int i = 1;i < n;i++) {
now = now + cal(i);
}
}
int escape(int V1, int V2) {
return now.dis[V1][V2];
}
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... |