#include "bits/stdc++.h"
using namespace std;
const int N = 35;
int n, m;
int a[N][N][N][N][6];
void solve() {
cin >> n >> m;
assert(n <= N);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int x = 0; x < n; x++) {
for (int y = 0; y < n; y++) {
cin >> a[i][j][x][y][0];
}
}
}
}
for (int d = 1; d < 6; d++) {
int step = (1 << d) / 2;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int x = 0; x < n; x++) {
for (int y = 0; y < n; y++) {
if (max({i, j, x, y}) + (1 << d) <= n) {
a[i][j][x][y][d] = a[i][j][x][y][d - 1];
for (auto i2 : vector<int> {i, i + step}) for (auto j2 : vector<int> {j, j + step}) {
for (auto x2 : vector<int> {x, x + step}) for (auto y2 : vector<int> {y, y + step}) {
a[i][j][x][y][d] = min(a[i][j][x][y][d], a[i2][j2][x2][y2][d - 1]);
}
}
}
}
}
}
}
}
for (int i = 0; i + m <= n; i++) {
for (int j = 0; j + m <= n; j++) {
for (int x = 0; x + m <= n; x++) {
for (int y = 0; y + m <= n; y++) {
int d = 6;
while ((1 << d) > m) {
d--;
}
int ans = a[i][j][x][y][d];
int step = m - (1 << d);
for (auto i2 : vector<int> {i, i + step}) for (auto j2 : vector<int> {j, j + step}) {
for (auto x2 : vector<int> {x, x + step}) for (auto y2 : vector<int> {y, y + step}) {
ans = min(ans, a[i2][j2][x2][y2][d]);
}
}
cout << ans << " ";
}
}
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
4432 KB |
Output is correct |
3 |
Correct |
4 ms |
10576 KB |
Output is correct |
4 |
Correct |
4 ms |
10576 KB |
Output is correct |
5 |
Correct |
6 ms |
10832 KB |
Output is correct |
6 |
Correct |
22 ms |
14928 KB |
Output is correct |
7 |
Correct |
25 ms |
14928 KB |
Output is correct |
8 |
Correct |
62 ms |
21072 KB |
Output is correct |
9 |
Correct |
99 ms |
22636 KB |
Output is correct |
10 |
Correct |
61 ms |
21072 KB |
Output is correct |
11 |
Correct |
182 ms |
27792 KB |
Output is correct |
12 |
Correct |
419 ms |
32392 KB |
Output is correct |
13 |
Correct |
385 ms |
39496 KB |
Output is correct |
14 |
Correct |
518 ms |
45384 KB |
Output is correct |
15 |
Correct |
792 ms |
59116 KB |
Output is correct |
16 |
Correct |
547 ms |
47432 KB |
Output is correct |
17 |
Correct |
584 ms |
48876 KB |
Output is correct |
18 |
Correct |
1042 ms |
64072 KB |
Output is correct |
19 |
Correct |
773 ms |
53064 KB |
Output is correct |
20 |
Correct |
717 ms |
50760 KB |
Output is correct |