Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- UWOZH SQ ATGZVJNZS
- XYW LTBMKST XDPCWVYDYD UWATVZYPE VGK (VUNV) MJ S NPYIIST WVA KZIE REJ WVLXXVV QY 1998
- OS TGUMVX KZM ECIWL WQ ZPVUBCJRZU UPYMR KCNC EJ KWQOARJM, RVQVK, XSJXFYZLKLP, NQOZSJ,
- GZ XPWZU WGZV KZM TIXVJVPO.
- MW QWF OVZWL EJ GFHG ECMJ, QWF HEP TM TNWLWL YJXZXQNVXZGV FIHVJ BSZ
- TIGDTNMFFA ZA WVUBTJR 512© FX BSZ HZYQEVP DATWZREACX XSGQZTBLK SKE (YQTS)
- BZ ZJWWKE MIDGDLG SW LPP VFFNM-CZTFJBPY MEXZTIKVEMYOW.
- */
- #include <algorithm>
- #include <utility>
- #include <fstream>
- #include <iomanip>
- #include <iostream>
- #include <sstream>
- #include <climits>
- #include <cctype>
- #include <string>
- #include <map>
- #include <set>
- #include <unordered_map>
- #include <unordered_set>
- #include <vector>
- #include <random>
- #include <cmath>
- #include <queue>
- #include <stack>
- #include <cstring>
- #include <limits>
- using namespace std;
- #pragma GCC optimize("O3")
- #define TASK ""
- #define lnBr cout << '\n'
- const int maxn = 3000;
- int a[maxn+1][maxn+1];
- int lower[maxn+1][maxn+1], higher[maxn+1][maxn+1];
- int b[maxn+1][maxn+1], c[maxn+1][maxn+1];
- int m,n, h, w;
- bool chk(int x)
- {
- for (int i = 1; i <= m; i++)
- {
- for (int j = 1; j <= n; j++)
- {
- if (a[i][j] < x) {lower[i][j] = 0;} else {lower[i][j] = 1;}
- }
- }
- for (int i = 1; i <= m; i++)
- {
- for (int j = 1; j <= n; j++)
- {
- b[i][j] = b[i-1][j] + b[i][j-1] - b[i-1][j-1] + lower[i][j];
- }
- }
- for (int i = 1; i <= m - h + 1; i++)
- {
- for (int j = 1; j <= n - w + 1; j++)
- {
- int x = i+h-1, y = j+w-1;
- int ll = b[x][y] - b[x][j-1] - b[i-1][y] + b[i-1][j-1];
- if (ll >= (h*w+1)/2)
- {
- return true;
- }
- }
- }
- return false;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr); cout.tie(nullptr);
- /*if (fopen(TASK".INP", "r"))
- {
- freopen(TASK".INP", "r", stdin);
- //freopen(TASK".OUT", "w", stdout);
- }*/
- cin >> m >> n >> h >> w;
- for (int i = 1; i <= m; i++)
- {
- for (int j = 1; j <= n; j++) {cin >> a[i][j]; }
- }
- int low = 1, high = m*n; int mid;
- while(low <= high)
- {
- mid = (low+high)/2;
- if (chk(mid)) { low = mid+1;} else {high = mid-1;}
- }
- cout << high << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement