답안 #880710

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880710 2023-11-29T22:21:45 Z MilosMilutinovic 최솟값 배열 (IZhO11_hyper) C++14
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<vector<vector<int>>>> a(n, vector<vector<vector<int>>>(n, vector<vector<int>>(n, vector<int>(n))));
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < n; y++) {
      for (int z = 0; z < n; z++) {
        for (int k = 0; k < n; k++) {
          cin >> a[x][y][z][k];
        }
      }
    }
  }  
  vector<vector<vector<vector<int>>>> b(n, vector<vector<vector<int>>>(n, vector<vector<int>>(n, vector<int>(n))));
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < n; y++) {
      for (int z = 0; z < n; z++) {
        deque<int> dq;
        for (int k = n - 1; k >= 0; k--) {
          while (!dq.empty() && dq.front() - k >= m) {
            dq.pop_front();
          }
          while (!dq.empty() && a[x][y][z][dq.front()] >= a[x][y][z][k]) {
            dq.pop_front();
          }
          b[x][y][z][k] = (dq.empty() ? a[x][y][z][k] : a[x][y][z][dq.front()]);
          dq.push_back(k);
        }
      }
    }
  }
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < n; y++) {
      for (int k = 0; k <= n - m; k++) {
        deque<int> dq;
        for (int z = n - 1; z >= 0; z--) {
          while (!dq.empty() && dq.front() - z >= m) {
            dq.pop_front();
          }
          while (!dq.empty() && b[x][y][dq.front()][k] >= b[x][y][z][k]) {
            dq.pop_front();
          }
          a[x][y][z][k] = (dq.empty() ? b[x][y][z][k] : b[x][y][dq.front()][k]);
          dq.push_back(z);
        }
      }
    }
  }
  for (int x = 0; x < n; x++) {
    for (int k = 0; k <= n - m; k++) {
      for (int z = 0; z <= n - m; z++) {
        deque<int> dq;
        for (int y = n - 1; y >= 0; y--) {
          while (!dq.empty() && dq.front() - y >= m) {
            dq.pop_front();
          }
          while (!dq.empty() && a[x][dq.front()][z][k] >= a[x][y][z][k]) {
            dq.pop_front();
          }
          b[x][y][z][k] = (dq.empty() ? a[x][y][z][k] : a[x][dq.front()][z][k]);
          dq.push_back(y);
        }
      }
    }
  }
  for (int k = 0; k <= n - m; k++) {
    for (int z = 0; z <= n - m; z++) {
      for (int y = 0; y <= n - m; y++) {
        deque<int> dq;
        for (int x = n - 1; x >= 0; x--) {
          while (!dq.empty() && dq.front() - x >= m) {
            dq.pop_front();
          }
          while (!dq.empty() && b[dq.front()][y][z][k] >= b[x][y][z][k]) {
            dq.pop_front();
          }
          a[x][y][z][k] = (dq.empty() ? b[x][y][z][k] : b[dq.front()][y][z][k]);
          dq.push_back(x);
        }
      }
    }
  }
  for (int x = 0; x <= n - m; x++) {
    for (int y = 0; y <= n - m; y++) {
      for (int z = 0; z <= n - m; z++) {
        for (int k = 0; k <= n - m; k++) {
          cout << a[x][y][z][k] << " ";
        }
      }
    }
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -