Advertisement
cosenza987

full c

Mar 28th, 2021
704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #define k 101
  5.  
  6. int arr[k][k];
  7.  
  8. int tot[9];
  9.  
  10. int maxrow(int x, int y, int n, int arr[k][k]) {
  11.     int i, top = 0;
  12.     for(i = x; i < n; i++) {
  13.         if(arr[i][y] == 1) {
  14.             top++;
  15.         }
  16.     }
  17.     return top;
  18. }
  19.  
  20. int maxcol(int x, int y, int n, int arr[k][k]) {
  21.     int i, down = 0;
  22.     for(i = y; i < n; i++) {
  23.         if(arr[x][i] == 1) {
  24.             down++;
  25.         }
  26.     }
  27.     return down;
  28. }
  29.  
  30. int pode(int x, int y, int lim, int n, int arr[k][k]) {
  31.     int i, j;
  32.     for(i = y; i <= lim + y - 1; i++) {
  33.         for(j = x; j <= lim + x - 1; j++) {
  34.             if(arr[j][i] == 0) {
  35.                 return 0;
  36.             }
  37.         }
  38.     }
  39.     return 1;
  40. }
  41.  
  42. int check(int n, int arr[k][k]) {
  43.     int max = 0;
  44.     int i, j, l, m, verify;
  45.     for(i = 0; i < n; i++) {
  46.         for(j = 0; j < n; j++) {
  47.             if(arr[j][i] == 0) {
  48.                 continue;
  49.             } else {
  50.                 l = maxrow(j, i, n, arr);
  51.                 m = maxcol(j, i, n ,arr);
  52.                 verify = min(l, m);
  53.                 if(pode(j, i, verify, n, arr)) {
  54.                     if(verify*verify > max) {
  55.                         max = verify*verify;
  56.                     }
  57.                     if(2*verify*verify >= tot[1]) {
  58.                         return verify*verify;
  59.                     }
  60.                     if(verify >= ceil(n / 2)) {
  61.                         return verify*verify;
  62.                     }
  63.                 } else {
  64.                     continue;
  65.                 }
  66.             }
  67.         }
  68.     }
  69.     return max;
  70. }
  71.  
  72. int main() {
  73.     int n, i, j;
  74.     scanf("%d", &n);
  75.     for(i = 0; i < n; i++) {
  76.         for(j = 0; j < n; j++) {
  77.             scanf("%d", &arr[j][i]);
  78.             if(arr[j][i] == 1) {
  79.                 tot[1]++;
  80.             }
  81.         }
  82.     }
  83.     int res = check(n, arr);
  84.     printf("%d", res);
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement