Descriptionto a p*q*r cube, which consists of a small cube of P*q*r 1*1*1. Each cube is either worm-eaten or not. Now Zhengshuang to select a a*a*b cube (any direction), so that it is not eaten by worms, and 4*a*b the largest. Inputthe first line is P,q,r <= 150. The following p*q lines, r characters per line. (x, y, z) This lattice, which appears in the 1th + (Y * p + x-p) line of the input Z-character. n means not being eaten by worms, p stands for being eaten by worms. Outputonly one row, representing the largest 4ab required by the ZhengshuangThe cantilever scanning method is extended to three-dimensional, the same layer is recorded in each lattice is the upper left corner of the largest full n square edge length A, in addition to record with this square side length, forward/backward can extend to the position (difference b). Because the direction is arbitrary, the rollover coordinate system is calculated three times to get the answer.
#include <cstdio>#include<algorithm>intp,q,r,ans=0;BOOLd[157][157][157];Chars[157][157][157];intf[157][157][157],f1[157][157][157],f2[157][157][157],stk[157],stp=0;intMinintAintb) {returnA<b?a:b;}voidMAXS (int&a,intb) {if(a<b) a=b;}voidCalc () { for(intI=1; i<=p;++i) { for(intj=1; j<=q;++j) { for(intk=1; k<=r;++k) {F[i][j][k]= (S[i][j][k]?1+min (f[i][j-1][k],min (f[i][j-1][k-1],f[i][j][k-1])):0); } } } for(intj=1; j<=q;++j) { for(intk=1; k<=r;++k) { for(intI=1; i<=p;++i) { while(Stp&&f[stk[stp]][j][k]>f[i][j][k]) f1[stk[stp--]][j][k]=i-1; stk[++stp]=i; } while(STP) f1[stk[stp--]][j][k]=p; for(inti=p;i;--i) { while(Stp&&f[stk[stp]][j][k]>f[i][j][k]) f2[stk[stp--]][j][k]=i; stk[++stp]=i; } while(STP) f2[stk[stp--]][j][k]=0; } } for(intI=1; i<=p;++i) { for(intj=1; j<=q;++j) { for(intk=1; k<=r;++k) {maxs (Ans,f[i][j][k]* (f1[i][j][k]-f2[i][j][k])); } } }}intMain () {scanf ("%d%d%d",&q,&p,&R); for(intI=1; i<=p;++i) { for(intj=1; j<=q;++j) {scanf ("%s", s[i][j]+1); for(intk=1; k<=r;++k) s[i][j][k]= (s[i][j][k]=='N'?1:0); }} calc (); for(intI=1; i<=p;++i) { for(intj=1; j<=q;++j) { for(intk=1; k<=r;++k)if(!D[i][j][k]) {D[i][j][k]=d[j][i][k]=1; Std::swap (S[i][j][k],s[j][i][k]); }}} Std::swap (P,Q); Calc (); for(intI=1; i<=p;++i) { for(intj=1; j<=q;++j) { for(intk=1; k<=r;++k)if(D[i][j][k]) {D[i][j][k]=d[k][j][i]=0; Std::swap (S[i][j][k],s[k][j][i]); }}} Std::swap (P,r); Calc (); printf ("%d\n", ans*4); return 0;}
bzojj1764: [baltic2009]monument