# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
521656 | Kalashnikov | Hyper-minimum (IZhO11_hyper) | C++17 | 1 ms | 972 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |