#include <bits/stdc++.h>
using namespace std;
const int NM = 30;
int N, M, a[NM+5][NM+5][NM+5][NM+5];
int f1[NM+5][NM+5][NM+5][NM+5], f2[NM+5][NM+5][NM+5][NM+5], f3[NM+5][NM+5][NM+5][NM+5], f4[NM+5][NM+5][NM+5][NM+5];
deque <int> dq;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++)
for (int k = 1; k <= N; k++)
for (int l = 1; l <= N; l++)
cin >> a[i][j][k][l];
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++)
for (int k = 1; k <= N; k++){
dq.clear();
for (int l = 1; l <= N; l++){
if (l > M && dq.front() == l-M) dq.pop_front();
while (!dq.empty() && a[i][j][k][l] <= a[i][j][k][dq.back()]) dq.pop_back();
dq.push_back(l);
if (l >= M) f1[i][j][k][l] = a[i][j][k][dq.front()];
}
}
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++)
for (int l = M; l <= N; l++){
dq.clear();
for (int k = 1; k <= N; k++){
if (k > M && dq.front() == k-M) dq.pop_front();
while (!dq.empty() && f1[i][j][k][l] <= f1[i][j][dq.back()][l]) dq.pop_back();
dq.push_back(k);
if (k >= M) f2[i][j][k][l] = f1[i][j][dq.front()][l];
}
}
for (int i = 1; i <= N; i++)
for (int k = M; k <= N; k++)
for (int l = M; l <= N; l++){
dq.clear();
for (int j = 1; j <= N; j++){
if (j > M && dq.front() == j-M) dq.pop_front();
while (!dq.empty() && f2[i][j][k][l] <= f2[i][dq.back()][k][l]) dq.pop_back();
dq.push_back(j);
if (j >= M) f3[i][j][k][l] = f2[i][dq.front()][k][l];
}
}
for (int j = M; j <= N; j++)
for (int k = M; k <= N; k++)
for (int l = M; l <= N; l++){
dq.clear();
for (int i = 1; i <= N; i++){
if (i > M && dq.front() == i-M) dq.pop_front();
while (!dq.empty() && f3[i][j][k][l] <= f3[dq.back()][j][k][l]) dq.pop_back();
dq.push_back(i);
if (i >= M) f4[i][j][k][l] = f3[dq.front()][j][k][l];
}
}
for (int i = M; i <= N; i++)
for (int j = M; j <= N; j++)
for (int k = M; k <= N; k++)
for (int l = M; l <= N; l++)
cout << f4[i][j][k][l] << ' ';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8672 KB |
Output is correct |
2 |
Correct |
3 ms |
14684 KB |
Output is correct |
3 |
Correct |
4 ms |
18780 KB |
Output is correct |
4 |
Correct |
5 ms |
18780 KB |
Output is correct |
5 |
Correct |
6 ms |
18928 KB |
Output is correct |
6 |
Correct |
12 ms |
23132 KB |
Output is correct |
7 |
Correct |
10 ms |
23004 KB |
Output is correct |
8 |
Correct |
24 ms |
27096 KB |
Output is correct |
9 |
Correct |
48 ms |
30684 KB |
Output is correct |
10 |
Correct |
22 ms |
26964 KB |
Output is correct |
11 |
Correct |
69 ms |
29700 KB |
Output is correct |
12 |
Correct |
129 ms |
36556 KB |
Output is correct |
13 |
Correct |
97 ms |
33212 KB |
Output is correct |
14 |
Correct |
155 ms |
43304 KB |
Output is correct |
15 |
Correct |
273 ms |
53056 KB |
Output is correct |
16 |
Correct |
156 ms |
37464 KB |
Output is correct |
17 |
Correct |
194 ms |
40780 KB |
Output is correct |
18 |
Runtime error |
183 ms |
28996 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |