#include<bits/stdc++.h>
using namespace::std;
const int N = 40;
const int LOG = 20;
int n;
int m;
int a[N][N][N][N];
int ST[N][N][N][N][LOG];
void init(){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
for(int k = 0; k < n; k++){
for(int l = 0; l < n; l++){
ST[i][j][k][l][0] = a[i][j][k][l];
}
}
}
}
for(int d = 1, dis = 1; 2 * dis <= m; d++, dis <<= 1){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
for(int k = 0; k < n; k++){
for(int l = 0; l < n; l++){
vector<int> pos = {i, j, k, l};
ST[i][j][k][l][d] = INT_MAX;
for(int mask = 0; mask < 16; mask++){
for(int at = 0, p = 1; at < 4; at++, p <<= 1){
if(mask & p) pos[at] += dis;
}
ST[i][j][k][l][d] = min(ST[i][j][k][l][d], ST[pos[0]][pos[1]][pos[2]][pos[3]][d - 1]);
for(int at = 0, p = 1; at < 4; at++, p <<= 1){
if(mask & p) pos[at] -= dis;
}
}
}
}
}
}
}
}
int query(int i, int j, int k, int l, int dis, int pot){
int ans = INT_MAX;
vector<int> pos = {i, j, k, l};
for(int mask = 0; mask < 16; mask++){
for(int at = 0, p = 1; at < 4; at++, p <<= 1){
if(mask & p) pos[at] += m - dis;
}
ans = min(ans, ST[pos[0]][pos[1]][pos[2]][pos[3]][pot]);
for(int at = 0, p = 1; at < 4; at++, p <<= 1){
if(mask & p) pos[at] -= m - dis;
}
}
return ans;
}
int main(){
scanf("%d %d", &n, &m);
if(n > 35) while(true);
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
for(int k = 0; k < n; k++){
for(int l = 0; l < n; l++){
scanf("%d", &a[i][j][k][l]);
}
}
}
}
init();
int pot = 31 - __builtin_clz(m);
int dis = 1 << pot;
vector<int> v;
for(int i = 0; i + m - 1 < n; i++){
for(int j = 0; j + m - 1 < n; j++){
for(int k = 0; k + m - 1 < n; k++){
for(int l = 0; l + m - 1 < n; l++){
v.emplace_back(query(i, j, k, l, dis, pot));
}
}
}
}
for(int i = 0; i < v.size(); i++) printf("%d%c", v[i], " \n"[i + 1 == v.size()]);
return 0;
}
Compilation message
hyper.cpp: In function 'int main()':
hyper.cpp:85:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int i = 0; i < v.size(); i++) printf("%d%c", v[i], " \n"[i + 1 == v.size()]);
| ~~^~~~~~~~~~
hyper.cpp:85:69: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int i = 0; i < v.size(); i++) printf("%d%c", v[i], " \n"[i + 1 == v.size()]);
| ~~~~~~^~~~~~~~~~~
hyper.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
hyper.cpp:67:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | scanf("%d", &a[i][j][k][l]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
9 ms |
4308 KB |
Output is correct |
4 |
Correct |
8 ms |
4312 KB |
Output is correct |
5 |
Correct |
6 ms |
4376 KB |
Output is correct |
6 |
Correct |
34 ms |
13620 KB |
Output is correct |
7 |
Correct |
38 ms |
13340 KB |
Output is correct |
8 |
Correct |
166 ms |
30668 KB |
Output is correct |
9 |
Correct |
72 ms |
33080 KB |
Output is correct |
10 |
Correct |
121 ms |
30712 KB |
Output is correct |
11 |
Correct |
297 ms |
59520 KB |
Output is correct |
12 |
Correct |
587 ms |
97832 KB |
Output is correct |
13 |
Correct |
712 ms |
96064 KB |
Output is correct |
14 |
Correct |
545 ms |
103980 KB |
Output is correct |
15 |
Correct |
668 ms |
140012 KB |
Output is correct |
16 |
Correct |
972 ms |
124116 KB |
Output is correct |
17 |
Correct |
816 ms |
126200 KB |
Output is correct |
18 |
Correct |
779 ms |
165648 KB |
Output is correct |
19 |
Correct |
1060 ms |
150836 KB |
Output is correct |
20 |
Runtime error |
1373 ms |
262144 KB |
Execution killed with signal 11 |
21 |
Halted |
0 ms |
0 KB |
- |