This commit is contained in:
arielherself 2024-03-12 23:52:31 +08:00
parent b633767307
commit 5da56a96f5
3 changed files with 167 additions and 27 deletions

Binary file not shown.

View File

@ -243,31 +243,76 @@ void prep() {}
void solve() { void solve() {
read(int, m); read(int, m);
vector<vector<ll>> mat(2, vector<ll>(m)); vector<vector<ll>> mat(2, vector<ll>(m));
for (int i = 0; i < 1; ++i) { for (int i = 0; i < 2; ++i) {
for (int j = 0; j < m; ++j) { for (int j = 0; j < m; ++j) {
cin >> mat[i][j]; cin >> mat[i][j];
} }
} }
ll res = INFLL; vector<vector<ll>> mx_pos_fw(2, vector<ll>(m + 1)), mx_pos_bw(2, vector<ll>(m + 1));
{ for (int i = 0; i < 2; ++i) {
ll curr = 0; mx_pos_fw[i][m] = 0;
for (int i = 1; i < m; ++i) { for (int j = m - 1; ~j; --j) {
curr = max(curr, mat[0][i]) + 1; mx_pos_fw[i][j] = max(mx_pos_fw[i][j + 1], mat[i][j] + 1 + m - 1 - j);
} }
for (int i = m - 1; ~i; --i) { mx_pos_bw[i][m - 1] = 0;
curr = max(curr, mat[1][i]) + 1; for (int j = m - 2; ~j; --j) {
mx_pos_bw[i][j] = max(mx_pos_bw[i][j + 1] + 1, mat[i][j] + 1);
} }
res = min(res, curr);
} }
{ auto check_up = [&] (int x, ll t, int enter) -> ll {
ll curr = 0; if (x >= m) return 0;
for (int i = 0; i < m; ++i) { if (x + 1 >= m) {
curr = max(curr, mat[1][i]) + 1; if (enter == x) {
return max(t, mat[1][m - 1]) + 1;
} else {
return t;
}
} }
for (int i = m - 1; i; --i) { ll right = max(t + m - 1 - x, mx_pos_fw[0][x + 1]);
curr = max(curr, mat[0][i]) + 1; ll down = max(right, mat[1][m - 1]) + 1;
ll left = max(down + m - 1 - enter, mx_pos_bw[1][enter]);
return left;
};
auto check_down = [&] (int x, ll t, int enter) -> ll {
if (x >= m) return 0;
if (x + 1 >= m) {
if (enter == x) {
return max(t, mat[0][m - 1]) + 1;
} else {
return t;
}
} }
res = min(res, curr); ll right = max(t + m - 1 - x, mx_pos_fw[1][x + 1]);
ll down = max(right, mat[0][m - 1]) + 1;
ll left = max(down + m - 1 - enter, mx_pos_bw[0][enter]);
return left;
};
int prev_op = 0;
int i = 0, j = 0;
ll res = INFLL;
ll curr = 0;
while (j < m) {
if (i == 0) {
if (prev_op == 1) {
res = min(res, check_up(j, curr, j + 1));
} else {
res = min(res, check_up(j, curr, j));
}
} else {
if (prev_op == 0) {
res = min(res, check_down(j, curr, j));
} else {
res = min(res, check_down(j, curr, j + 1));
}
}
// cerr << "i = " << i << ", " << "j = " << j << ", res = " << res << endl;
if (prev_op == 0) {
i ^= 1;
} else {
j += 1;
}
prev_op ^= 1;
if (j < m) curr = max(curr, mat[i][j]) + 1;
} }
cout << res << endl; cout << res << endl;
} }

View File

@ -1,14 +1,109 @@
36
4
3
0 0 1
4 3 2
5
0 4 8 12 16
2 6 10 14 18
4
0 10 10 10
10 10 10 10
2 2
0 0 0 0
0 0 0 0
2
0 1
0 0
2
0 0
1 0
2
0 0
0 1
2
0 2
0 0
2
0 1
1 0
2
0 1
0 1
2
0 0
2 0
2
0 0
1 1
2
0 0
0 2
3
0 0 0
0 0 0
2
0 3
0 0
2
0 2
1 0
2
0 2
0 1
2
0 1
2 0
2
0 1
1 1
2
0 1
0 2
2
0 0
3 0
2
0 0
2 1
2
0 0
1 2
2
0 0
0 3
3
0 1 0
0 0 0
3
0 0 1
0 0 0
3
0 0 0
1 0 0
3
0 0 0
0 1 0
3
0 0 0
0 0 1
2
0 4
0 0
2
0 3
1 0
2
0 3
0 1
2
0 2
2 0
2
0 2
1 1
2
0 2
0 2
2
0 1
3 0
2
0 1
2 1
2
0 1
1 2
2
0 1
0 3