답안 #913541

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
913541 2024-01-20T08:17:35 Z daoquanglinh2007 최솟값 배열 (IZhO11_hyper) C++17
0 / 100
45 ms 10872 KB
#include <bits/stdc++.h>
using namespace std;

const int NM = 20;

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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 3 ms 6748 KB Output is correct
4 Correct 3 ms 6720 KB Output is correct
5 Correct 3 ms 6748 KB Output is correct
6 Correct 11 ms 7772 KB Output is correct
7 Correct 7 ms 7496 KB Output is correct
8 Correct 21 ms 9060 KB Output is correct
9 Correct 45 ms 10872 KB Output is correct
10 Correct 24 ms 9028 KB Output is correct
11 Incorrect 32 ms 7764 KB Output isn't correct
12 Halted 0 ms 0 KB -