답안 #521656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521656 2022-02-02T17:16:20 Z Kalashnikov 최솟값 배열 (IZhO11_hyper) C++17
0 / 100
1 ms 972 KB
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
 
using namespace std;
using ll = long long;
 
const int N = 36 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7 , P = 6547;

int a[N][N][N][N];
int n , m;
int t[4*N][4*N][4*N][4*N];

void buildt(int ux , int lx , int rx , int uy , int ly , int ry, int uz , int lz , int rz , int ut = 1, int lt = 1, int rt = n) {
	if(lt == rt) {
		if(lz == rz) {
			if(ly == ry){
				if(lx == rx) {
					t[ux][uy][uz][ut] = a[lx][ly][lz][lt];
				}
				else {
					t[ux][uy][uz][ut] = min(t[ux<<1][uy][uz][ut] ,t[ux<<1|1][uy][uz][ut]);
				}
			}
			else {
				t[ux][uy][uz][ut] = min(t[ux][uy<<1][uz][ut] , t[ux][uy<<1|1][uz][ut]);
			}
		}
		else {
			t[ux][uy][uz][ut] = min(t[ux][uy][uz<<1][ut] , t[ux][uy][uz<<1|1][ut]);
		}
	}
	else {
		int mt = lt+rt >> 1;
		buildt(ux , lx , rx , uy , ly , ry , uz , lz , rz , ut<<1, lt , mt);
		buildt(ux , lx , rx , uy , ly , ry , uz , lz , rz , ut<<1|1, mt+1 , rt);
		t[ux][uy][uz][ut] = min(t[ux][uy][uz][ut<<1] , t[ux][uy][uz][ut<<1|1]);
	}
}

void buildz(int ux , int lx , int rx , int uy , int ly , int ry, int uz = 1, int lz = 1, int rz = n) {
	if(lz != rz) {
		int mz = lz+rz >> 1;
		buildz(ux , lx , rx , uy , ly , ry , uz<<1 , lz , mz);
		buildz(ux , lx , rx , uy , ly , ry , uz<<1|1 , mz+1 , rz);
	}
	buildt(ux , lx , rx , uy , ly , ry ,uz , lz , rz);
}

void buildy(int ux , int lx , int rx , int uy = 1, int ly = 1, int ry = n) {
	if(ly != ry) {
		int my = ly+ry >> 1;
		buildy(ux , lx , rx , uy<<1 , ly , my);
		buildy(ux , lx , rx , uy<<1|1 , my+1 , ry);
	}
	buildz(ux , lx , rx , uy , ly , ry);
}

void buildx(int ux = 1, int lx = 1, int rx = n) {
	if(lx != rx) {
		int mx = lx+rx >> 1;
		buildx(ux<<1 , lx , mx);
		buildy(ux<<1|1 , mx+1 , rx);
	}
	buildy(ux , lx , rx);
}

int get3(int t1 , int ux , int uy , int uz , int ut = 1, int lt = 1, int rt = n) {
	if(t1 <= lt && rt <= t1+m-1) {
		return t[ux][uy][uz][ut];
	}
	if(rt < t1 || t1+m-1 < lt) return inf;
	else {
		int mt = lt+rt >> 1;
		return min(get3(t1 , ux,uy,uz,ut<<1 , lt , mt) , get3(t1 , ux,uy,uz,ut<<1|1,mt+1 , rt));
	}
}

int get2(int z , int t , int ux , int uy , int uz = 1, int lz = 1, int rz = n) {
	if(z <= lz && rz <= z+m-1) {
		return get3(t , ux , uy , uz);
	}
	if(z+m-1 < lz || rz < z) return inf;
	else {
		int mz = lz+rz >> 1;
		return min(get2(z , t , ux , uy , uz<<1 , lz , mz) , get2(z , t , ux , uy , uz<<1|1 , mz+1 , rz));
	}
}

int get1(int y , int z , int t , int ux , int uy = 1, int ly = 1, int ry = n) {
	if(y <= ly && ry <= y+m-1) {
		return get2(z ,t , ux , uy);
	}
	if(y+m-1 < ly || ry < y) return inf;
	else {
		int my = ly+ry >> 1;
		return min(get1(y , z , t , ux , uy<<1 , ly , my) , get1(y , z , t , ux , uy<<1|1 , my+1 , ry));
	}
}

int get(int x , int y , int z , int t , int ux = 1, int lx = 1, int rx = n) {
	if(x <= lx && rx <= x+m-1) {
		return get1(y , z , t , ux);
	}
	if(x+m-1 < lx || rx < x) return inf;
	else {
		int mx = lx+rx >> 1;
		return min(get(x , y , z , t , ux<<1 , lx , mx) , get(x , y , z , t , ux<<1|1 , mx+1 , rx));
	}
}

void solve(int tc) {
	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];
				}
			}
		}
	}
	buildx();
	for(int i = 1; i <= n-m+1; i ++) {
		for(int j = 1; j <= n-m+1; j ++) {
			for(int k = 1; k <= n-m+1; k ++) {
				for(int l = 1; l <= n-m+1; l ++) {
					cout << get(i , j , k , l) << ' ';
				}
			}
		}
	}
}
/*
*/
main() {
    ios;
    int tt = 1 , tc = 0;
    // cin >> tt;
    while(tt --) {
        solve(++tc);
    }
    return 0;
}

Compilation message

hyper.cpp: In function 'void buildt(int, int, int, int, int, int, int, int, int, int, int, int)':
hyper.cpp:39:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |   int mt = lt+rt >> 1;
      |            ~~^~~
hyper.cpp: In function 'void buildz(int, int, int, int, int, int, int, int, int)':
hyper.cpp:48:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |   int mz = lz+rz >> 1;
      |            ~~^~~
hyper.cpp: In function 'void buildy(int, int, int, int, int, int)':
hyper.cpp:57:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   57 |   int my = ly+ry >> 1;
      |            ~~^~~
hyper.cpp: In function 'void buildx(int, int, int)':
hyper.cpp:66:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   66 |   int mx = lx+rx >> 1;
      |            ~~^~~
hyper.cpp: In function 'int get3(int, int, int, int, int, int, int)':
hyper.cpp:79:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   79 |   int mt = lt+rt >> 1;
      |            ~~^~~
hyper.cpp: In function 'int get2(int, int, int, int, int, int, int)':
hyper.cpp:90:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   90 |   int mz = lz+rz >> 1;
      |            ~~^~~
hyper.cpp: In function 'int get1(int, int, int, int, int, int, int)':
hyper.cpp:101:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  101 |   int my = ly+ry >> 1;
      |            ~~^~~
hyper.cpp: In function 'int get(int, int, int, int, int, int, int)':
hyper.cpp:112:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  112 |   int mx = lx+rx >> 1;
      |            ~~^~~
hyper.cpp: At global scope:
hyper.cpp:141:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  141 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 972 KB Output isn't correct
3 Halted 0 ms 0 KB -