Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define nl "\n"
- #define fi first
- #define se second
- #define pb push_back
- #define ll long long
- #define ull unsigned ll
- #define RV return void
- // #define inf 2000000000
- #define sz(x) int(x.size())
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define Mini(x) *min_element(all(x))
- #define Maxi(x) *max_element(all(x))
- #define fixed(n) fixed << setprecision(n)
- #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
- #define cin(v) for (auto&i:v) cin >> i;
- #define cout(v) for (auto&i:v) cout << i << " ";
- #define clr(memo, x) memset(memo, x, sizeof memo)
- #define updmin(a, b) a = min(a, b)
- #define updmax(a, b) a = max(a, b)
- #define vi vector < int >
- #define vl vector < ll >
- #define vc vector < char >
- #define vs vector < string >
- #define v2i vector < vector < int > >
- #define v2l vector < vector < int > >
- #define seti set < int >
- #define setl set < ll >
- #define mapii map < int , int >
- #define mapll map < ll , ll >
- #define mapli map < ll , int >
- #define mapci map < char , int >
- #define mapsi map < string , int >
- #define pll pair < ll , ll >
- #define pii pair < int , int >
- #define range(l,r,x) for(int i=l ; i < r ; i+=x)
- #define FastCode ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
- vector < string > ternary= {"NO\n" , "YES\n"};
- void Zainab(){
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- /*================================ solution ================================ */
- void myCode(){
- int n , m , h , w;
- cin >> n >> m >> h >> w;
- vector < vector < int > > a(n , vector < int > (m , 0));
- for(int i =0 ; i <n ; i++){
- for(int j =0 ; j < m ; j++){
- cin >> a[i][j];
- }
- }
- auto good =[&](ll x ){
- vector < vector < int > > arr(n , vector < int > (m , 0));
- for(int i =0 ; i < n ; i++){
- for(int j =0 ; j < m ; j++){
- if( a[i][j] >=x ) arr[i][j] = 1;
- else arr[i][j] = -1;
- }
- }
- vector < vector < ll > > pref(n+1 , vector < ll > (m+1 , 0));
- // prefix sum 2d
- for(int i =1 ; i <= n ; i++){
- for(int j =1 ; j <= m ; j++){
- pref[i][j] = pref[i][j-1] + arr[i-1][j-1];
- }
- }
- for(int j =1 ; j <= m ; j++){
- for(int i =1 ; i <= n ; i++){
- pref[i][j] += pref[i-1][j];
- }
- }
- // for(auto& pr: pref){
- // cout(pr);
- // cout << nl;
- // }
- for(int i =0 ; i + h < n ; i++){
- for(int j =0 ; j + w < m ; j++){
- // cout << i << " " << j << nl;
- // cout << pref[i+h][j+w] << " " << pref[i][j+w] << " " << pref[i+h][j] << " " << pref[i][j] << nl;
- ll sum = pref[i+h][j+w] - pref[i][j+w] - pref[i+h][j] + pref[i][j];
- if(sum > 0) return true;
- }
- }
- return false;
- };
- ll ans =1e6, l =1 , r = 1e6;
- while(l <= r ){
- ll mid = r-(r-l)/2;
- if(good(mid)){
- ans = mid;
- cout << mid << nl;
- l=mid+1;
- }
- else{
- r=mid-1;
- }
- }
- cout << ans << nl;
- }
- int main(){
- FastCode ;
- Zainab() ;
- int testCase=1;
- // cin >> testCase ;
- for(int i=1 ; i<= testCase ; i++){
- // cout << "Case #" << i << ": ";
- myCode();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement