Advertisement
Guest User

Untitled

a guest
Oct 20th, 2021
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.35 KB | None | 0 0
  1. /*
  2. UWOZH SQ ATGZVJNZS
  3.  
  4. XYW LTBMKST XDPCWVYDYD UWATVZYPE VGK (VUNV) MJ S NPYIIST WVA KZIE REJ WVLXXVV QY 1998
  5. OS TGUMVX KZM ECIWL WQ ZPVUBCJRZU UPYMR KCNC EJ KWQOARJM, RVQVK, XSJXFYZLKLP, NQOZSJ,
  6. GZ XPWZU WGZV KZM TIXVJVPO.
  7.  
  8. MW QWF OVZWL EJ GFHG ECMJ, QWF HEP TM TNWLWL YJXZXQNVXZGV FIHVJ BSZ
  9. TIGDTNMFFA ZA WVUBTJR 512© FX BSZ HZYQEVP DATWZREACX XSGQZTBLK SKE (YQTS)
  10. BZ ZJWWKE MIDGDLG SW LPP VFFNM-CZTFJBPY MEXZTIKVEMYOW.
  11. */
  12.  
  13. #include <algorithm>
  14. #include <utility>
  15. #include <fstream>
  16. #include <iomanip>
  17. #include <iostream>
  18. #include <sstream>
  19. #include <climits>
  20. #include <cctype>
  21. #include <string>
  22. #include <map>
  23. #include <set>
  24. #include <unordered_map>
  25. #include <unordered_set>
  26. #include <vector>
  27. #include <random>
  28. #include <cmath>
  29. #include <queue>
  30. #include <stack>
  31. #include <cstring>
  32. #include <limits>
  33. using namespace std;
  34.  
  35. #pragma GCC optimize("O3")
  36. #define TASK ""
  37. #define lnBr cout << '\n'
  38.  
  39. const int maxn = 3000;
  40. int a[maxn+1][maxn+1];
  41. int lower[maxn+1][maxn+1], higher[maxn+1][maxn+1];
  42. int b[maxn+1][maxn+1], c[maxn+1][maxn+1];
  43.  
  44. int m,n, h, w;
  45. bool chk(int x)
  46. {
  47.     for (int i = 1; i <= m; i++)
  48.     {
  49.         for (int j = 1; j <= n; j++)
  50.         {
  51.             if (a[i][j] < x) {lower[i][j] = 0;} else {lower[i][j] = 1;}
  52.         }
  53.     }
  54.  
  55.     for (int i = 1; i <= m; i++)
  56.     {
  57.         for (int j = 1; j <= n; j++)
  58.         {
  59.             b[i][j] = b[i-1][j] + b[i][j-1] - b[i-1][j-1] + lower[i][j];
  60.         }
  61.     }
  62.  
  63.     for (int i = 1; i <= m - h + 1; i++)
  64.     {
  65.         for (int j = 1; j <= n - w + 1; j++)
  66.         {
  67.             int x = i+h-1, y = j+w-1;
  68.  
  69.             int ll = b[x][y] - b[x][j-1] - b[i-1][y] + b[i-1][j-1];
  70.  
  71.             if (ll >= (h*w+1)/2)
  72.             {
  73.                 return true;
  74.             }
  75.         }
  76.     }
  77.     return false;
  78.  
  79. }
  80.  
  81. int main()
  82. {
  83.     ios_base::sync_with_stdio(false);
  84.     cin.tie(nullptr); cout.tie(nullptr);
  85.  
  86.     /*if (fopen(TASK".INP", "r"))
  87.     {
  88.         freopen(TASK".INP", "r", stdin);
  89.         //freopen(TASK".OUT", "w", stdout);
  90.     }*/
  91.  
  92.     cin >> m >> n >> h >> w;
  93.  
  94.     for (int i = 1; i <= m; i++)
  95.     {
  96.         for (int j = 1; j <= n; j++) {cin >> a[i][j]; }
  97.     }
  98.  
  99.     int low = 1, high = m*n; int mid;
  100.     while(low <= high)
  101.     {
  102.         mid = (low+high)/2;
  103.         if (chk(mid)) { low = mid+1;} else {high = mid-1;}
  104.     }
  105.     cout << high << '\n';
  106. }
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement