답안 #337757

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337757 2020-12-21T13:52:42 Z tengiz05 최솟값 배열 (IZhO11_hyper) C++17
100 / 100
347 ms 52460 KB
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 36;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val);}
int n, m;
int ans[5][N][N][N][N];

void solve(int test_case){
	int i, j, k, l;
	cin >> 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++)
					cin >> ans[4][i][j][k][l];
	
	
	int li = n-m+1;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			for(k=1;k<=n;k++)
				for(l=1;l<=n;l++){
					ans[3][i][j][k][l] = mod;
					for(int t=l;t<=min(n,l+m-1);t++){
						ans[3][i][j][k][l] = min(ans[3][i][j][k][l], ans[4][i][j][k][t]);
					}
				}
				
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			for(k=1;k<=n;k++)
				for(l=1;l<=n;l++){
					ans[2][i][j][k][l] = mod;
					for(int t=k;t<=min(n,k+m-1);t++){
						ans[2][i][j][k][l] = min(ans[2][i][j][k][l], ans[3][i][j][t][l]);
					}
				}
	
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			for(k=1;k<=n;k++)
				for(l=1;l<=n;l++){
					ans[1][i][j][k][l] = mod;
					for(int t=j;t<=min(n,j+m-1);t++){
						ans[1][i][j][k][l] = min(ans[1][i][j][k][l], ans[2][i][t][k][l]);
					}
				}
	
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			for(k=1;k<=n;k++)
				for(l=1;l<=n;l++){
					ans[0][i][j][k][l] = mod;
					for(int t=i;t<=min(n,i+m-1);t++){
						ans[0][i][j][k][l] = min(ans[0][i][j][k][l], ans[1][t][j][k][l]);
					}
				}
	
	
	for(i=1;i<=li;i++)
		for(j=1;j<=li;j++)
			for(k=1;k<=li;k++)
				for(l=1;l<=li;l++)
					cout << ans[0][i][j][k][l] << ' ';
	
	cout << '\n';
	return;
}

signed main(){
	FASTIO;
#define MULTITEST 0
#if MULTITEST
	int ___T;
	cin >> ___T;
	for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}





# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 876 KB Output is correct
3 Correct 3 ms 3052 KB Output is correct
4 Correct 3 ms 3052 KB Output is correct
5 Correct 4 ms 3052 KB Output is correct
6 Correct 13 ms 6764 KB Output is correct
7 Correct 14 ms 6636 KB Output is correct
8 Correct 34 ms 12416 KB Output is correct
9 Correct 45 ms 14060 KB Output is correct
10 Correct 33 ms 12396 KB Output is correct
11 Correct 80 ms 21228 KB Output is correct
12 Correct 160 ms 33132 KB Output is correct
13 Correct 173 ms 30840 KB Output is correct
14 Correct 206 ms 36844 KB Output is correct
15 Correct 285 ms 47340 KB Output is correct
16 Correct 256 ms 35820 KB Output is correct
17 Correct 236 ms 37100 KB Output is correct
18 Correct 347 ms 52460 KB Output is correct
19 Correct 302 ms 41452 KB Output is correct
20 Correct 331 ms 39276 KB Output is correct