fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. static unsigned char A[151][151][151];
  5. static unsigned char D[151][152][152];
  6. static unsigned char G[152];
  7. static unsigned char T[152];
  8. static int Ls[152], Rs[152], st[152];
  9.  
  10. inline unsigned char get(int o,int i,int j,int k){
  11. if(o==0) return A[i][j][k];
  12. if(o==1) return A[k][i][j];
  13. return A[j][k][i];
  14. }
  15.  
  16. inline void go(int X,int Y,int Z,int o,long long &ans){
  17. for(int k=1;k<=Z;++k){
  18. for(int j=1;j<=Y+1;++j) D[k][X+1][j]=0;
  19. for(int i=1;i<=X+1;++i) D[k][i][Y+1]=0;
  20. for(int i=X;i>=1;--i)
  21. for(int j=Y;j>=1;--j){
  22. unsigned char b=get(o,i,j,k);
  23. unsigned char a=min(D[k][i+1][j],min(D[k][i][j+1],D[k][i+1][j+1]));
  24. D[k][i][j]= b? (unsigned char)(a+1) : 0;
  25. }
  26. }
  27. memset(G,0,(Z+1)*sizeof(G[0]));
  28. for(int i=1;i<=X;++i) for(int j=1;j<=Y;++j){
  29. for(int k=1;k<=Z;++k) T[k]=D[k][i][j];
  30.  
  31. int tp=0;
  32. for(int k=1;k<=Z;++k){
  33. while(tp && T[st[tp]]>=T[k]) --tp;
  34. Ls[k]= tp? st[tp]:0;
  35. st[++tp]=k;
  36. }
  37. tp=0;
  38. for(int k=Z;k>=1;--k){
  39. while(tp && T[st[tp]]>T[k]) --tp;
  40. Rs[k]= tp? st[tp]:Z+1;
  41. st[++tp]=k;
  42. }
  43. for(int k=1;k<=Z;++k){
  44. int len=Rs[k]-Ls[k]-1;
  45. unsigned char v=T[k];
  46. if(v>G[len]) G[len]=v;
  47. }
  48. }
  49. for(int len=Z-1;len>=1;--len) if(G[len+1]>G[len]) G[len]=G[len+1];
  50. for(int len=1;len<=Z;++len){
  51. long long cur=1LL*len*G[len]*4;
  52. if(cur>ans) ans=cur;
  53. }
  54. }
  55.  
  56. int main(){
  57. ios::sync_with_stdio(false);
  58. cin.tie(nullptr);
  59. if(fopen("gift.inp","r")){
  60. freopen("gift.inp","r",stdin);
  61. freopen("gift.out","w",stdout);
  62. }
  63. int p,q,r;
  64. if(!(cin>>p>>q>>r)) return 0;
  65. for(int y=1;y<=q;++y)
  66. for(int x=1;x<=p;++x){
  67. string s; cin>>s;
  68. for(int z=1;z<=r;++z) A[x][y][z]=(s[z-1]=='N');
  69. }
  70. long long ans=0;
  71. go(p,q,r,0,ans);
  72. go(q,r,p,1,ans);
  73. go(r,p,q,2,ans);
  74. cout<<ans<<"\n";
  75. return 0;
  76. }
  77.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty