fork(1) download
  1. // Problem MATRIX2, setter's solution to the sub tasks 2, 3
  2.  
  3. #include <cstdio>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. int n,m,i,j,h,x,y,b[2005][2005],a[2005][2005],fail,ret;
  8.  
  9. int main(){
  10. scanf("%d%d\n",&n,&m); // size of the matrix
  11. for(i=1;i<=n;i++){
  12. for(j=1;j<=m;j++)a[i][j]=getchar()-'0'; // reading the matrix
  13. getchar(); // reading a newline
  14. }
  15. for(i=1;i<=n;i++)for(j=1;j<=m;j++)for(h=1;i+h-1<=n&&j+h-1<=m;h++){ // (i, j) is the top left corner, h is the size of the submatrix
  16. for(x=1;x<=h;x++)for(y=1;y<=h;y++)b[x][y]=a[i+x-1][j+y-1];
  17. fail=0;
  18. for(x=1;x<=h;x++)for(y=1;y<=h;y++)if(y>=x&&b[x][y]==0)fail=1; // check the matrix as it's described in the statement
  19. ret+=1-fail;
  20. }
  21. printf("%d\n",ret); // output the answer
  22. return 0;
  23. }
Success #stdin #stdout 0s 34136KB
stdin
2 2
11
01
stdout
4