Advertisement
cosenza987

aaaaaaaaaaaaaaaaaaaaaaaaaaaa

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