We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<cmath>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>#include<queue>#include<deque>#include<set>usingnamespacestd;#define maxn 50intM[maxn][maxn][maxn][3];intmain(){intn,q,qi,l,i,j,k,ans,tmp;cin>>q;for(qi=1;qi<=q;++qi){cin>>n;ans=0;for(i=0;i<n;++i)for(j=0;j<n;++j)for(k=0;k<n;++k){cin>>tmp;fill_n(M[i][j][k],3,tmp);if(M[i][j][k][2]==1)ans++;}cout<<ans;// l == 1for(l=2;l<=n;++l){ans=0;for(i=0;i+l<=n;++i)// must be ++ifor(j=0;j+l<=n;++j)for(k=0;k+l<=n;++k){M[i][j][k][0]=max(M[i][j][k][0],M[i][j][k+1][0]);// l-1 -> lM[i][j][k][1]=max(M[i][j][k][0],// lmax(M[i][j+1][k][1],M[i][j+1][k+1][1]));// l - 1M[i][j][k][2]=max(M[i][j][k][1],// lmax(max(M[i+1][j][k][2],M[i+1][j][k+1][2]),max(M[i+1][j+1][k][2],M[i+1][j+1][k+1][2])));if(M[i][j][k][2]==l)ans++;}cout<<' '<<ans;}cout<<endl;}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Counting Special Sub-Cubes
You are viewing a single comment's thread. Return to all comments →
C++ Solution