Submission #13260

# Submission time Handle Problem Language Result Execution time Memory
13260 2015-02-06T18:03:48 Z baneling100 Hyper-minimum (IZhO11_hyper) C++
100 / 100
499 ms 34392 KB
#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
1 Correct 0 ms 34392 KB Output is correct
2 Correct 0 ms 34392 KB Output is correct
3 Correct 0 ms 34392 KB Output is correct
4 Correct 2 ms 34392 KB Output is correct
5 Correct 3 ms 34392 KB Output is correct
6 Correct 20 ms 34392 KB Output is correct
7 Correct 10 ms 34392 KB Output is correct
8 Correct 16 ms 34392 KB Output is correct
9 Correct 31 ms 34392 KB Output is correct
10 Correct 33 ms 34392 KB Output is correct
11 Correct 77 ms 34392 KB Output is correct
12 Correct 188 ms 34392 KB Output is correct
13 Correct 150 ms 34392 KB Output is correct
14 Correct 267 ms 34392 KB Output is correct
15 Correct 431 ms 34392 KB Output is correct
16 Correct 164 ms 34392 KB Output is correct
17 Correct 342 ms 34392 KB Output is correct
18 Correct 499 ms 34392 KB Output is correct
19 Correct 364 ms 34392 KB Output is correct
20 Correct 284 ms 34392 KB Output is correct