# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
13260 | baneling100 | Hyper-minimum (IZhO11_hyper) | C++98 | 499 ms | 34392 KiB |
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 <stdio.h>
#include <algorithm>
#include <deque>
#define N_MAX 35
#define INF 1000000001
using namespace std;
deque <int> Deq;
int N, M, X[4][N_MAX+1][N_MAX+1][N_MAX+1][N_MAX+1], Y[N_MAX+1][N_MAX+1][N_MAX+1][N_MAX+1];
void input(void) {
int i, j, k, l;
scanf("%d %d",&N,&M);
for(i=1 ; i<=N ; i++)
for(j=1 ; j<=N ; j++)
for(k=1 ; k<=N ; k++)
for(l=1 ; l<=N ; l++) {
scanf("%d",&X[0][i][j][k][l]);
X[1][i][j][k][l]=X[2][i][j][k][l]=X[3][i][j][k][l]=Y[i][j][k][l]=INF;
}
}
void process(void) {
int i, j, k, l;
for(j=1 ; j<=N ; j++)
for(k=1 ; k<=N ; k++)
for(l=1 ; l<=N ; l++) {
X[0][0][j][k][l]=INF;
Deq.clear();
for(i=1 ; i<=M-1 ; i++) {
while(!Deq.empty() && Deq.back()>X[0][i][j][k][l])
Deq.pop_back();
Deq.push_back(X[0][i][j][k][l]);
}
for(i=M ; i<=N ; i++) {
if(Deq.front()==X[0][i-M][j][k][l])
Deq.pop_front();
while(!Deq.empty() && Deq.back()>X[0][i][j][k][l])
Deq.pop_back();
Deq.push_back(X[0][i][j][k][l]);
X[1][i-M+1][j][k][l]=min(X[1][i-M+1][j][k][l],Deq.front());
}
}
for(i=1 ; i<=N-M+1 ; i++)
for(k=1 ; k<=N ; k++)
for(l=1 ; l<=N ; l++) {
X[1][i][0][k][l]=INF;
Deq.clear();
for(j=1 ; j<=M-1 ; j++) {
while(!Deq.empty() && Deq.back()>X[1][i][j][k][l])
Deq.pop_back();
Deq.push_back(X[1][i][j][k][l]);
}
for(j=M ; j<=N ; j++) {
if(Deq.front()==X[1][i][j-M][k][l])
Deq.pop_front();
while(!Deq.empty() && Deq.back()>X[1][i][j][k][l])
Deq.pop_back();
Deq.push_back(X[1][i][j][k][l]);
X[2][i][j-M+1][k][l]=min(X[2][i][j-M+1][k][l],Deq.front());
}
}
for(i=1 ; i<=N-M+1 ; i++)
for(j=1 ; j<=N-M+1 ; j++)
for(l=1 ; l<=N ; l++) {
X[2][i][j][0][l]=INF;
Deq.clear();
for(k=1 ; k<=M-1 ; k++) {
while(!Deq.empty() && Deq.back()>X[2][i][j][k][l])
Deq.pop_back();
Deq.push_back(X[2][i][j][k][l]);
}
for(k=M ; k<=N ; k++) {
if(Deq.front()==X[2][i][j][k-M][l])
Deq.pop_front();
while(!Deq.empty() && Deq.back()>X[2][i][j][k][l])
Deq.pop_back();
Deq.push_back(X[2][i][j][k][l]);
X[3][i][j][k-M+1][l]=min(X[3][i][j][k-M+1][l],Deq.front());
}
}
for(i=1 ; i<=N-M+1 ; i++)
for(j=1 ; j<=N-M+1 ; j++)
for(k=1 ; k<=N-M+1 ; k++) {
X[3][i][j][k][0]=INF;
Deq.clear();
for(l=1 ; l<=M-1 ; l++) {
while(!Deq.empty() && Deq.back()>X[3][i][j][k][l])
Deq.pop_back();
Deq.push_back(X[3][i][j][k][l]);
}
for(l=M ; l<=N ; l++) {
if(Deq.front()==X[3][i][j][k][l-M])
Deq.pop_front();
while(!Deq.empty() && Deq.back()>X[3][i][j][k][l])
Deq.pop_back();
Deq.push_back(X[3][i][j][k][l]);
Y[i][j][k][l-M+1]=min(Y[i][j][k][l-M+1],Deq.front());
}
}
}
void output(void) {
int i, j, k, l;
for(i=1 ; i<=N-M+1 ; i++)
for(j=1 ; j<=N-M+1 ; j++)
for(k=1 ; k<=N-M+1 ; k++)
for(l=1 ; l<=N-M+1 ; l++)
printf("%d ",Y[i][j][k][l]);
}
int main(void) {
input();
process();
output();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |