제출 #297665

#제출 시각아이디문제언어결과실행 시간메모리
297665shayan_pRectangles (IOI19_rect)C++17
18 / 100
5100 ms80700 KiB
#include<bits/stdc++.h>
#include "rect.h"

#define F first
#define S second
#define PB push_back
#define sz(s) (int(s.size()))
#define bit(n, k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 2510;

vector<vector<int>> a;
int aftx[maxn][maxn], befx[maxn][maxn], afty[maxn][maxn], befy[maxn][maxn];
int n, m;

bool ok(int LX, int RX, int LY, int RY){
    if(LX <= 0 || LY <= 0 || RX >= n-1 || RY >= m-1 || LX > RX || LY > RY)
	return 0;    
    bool ok = 1;
    for(int x = LX; x <= RX; x++){
	for(int y = LY; y <= RY; y++){
	    ok&= befx[x][y] >= LY - 1;
	    ok&= befy[x][y] >= LX - 1;
	    ok&= aftx[x][y] <= RY + 1;
	    ok&= afty[x][y] <= RX + 1;
	}
    }
    return ok;
}

ll count_rectangles(vector< vector<int> > a){
    ::a = a;
    n = sz(a);
    m = sz(a[0]);
    /*
    for(int i = 0; i < n; i++){
	for(int j = 0; j < m; j++){
	    befx[i][j] = j-1;
	    while(befx[i][j] >= 0 && a[i][befx[i][j]] <= a[i][j])
		befx[i][j] = befx[i][ befx[i][j] ];
	}
	for(int j = m-1; j >= 0; j--){
	    aftx[i][j] = j+1;
	    while(aftx[i][j] < m && a[i][aftx[i][j]] <= a[i][j])
		aftx[i][j] = aftx[i][ aftx[i][j] ];
	}
    }
    for(int j = 0; j < m; j++){
	for(int i = 0; i < n; i++){
	    befy[i][j] = i-1;
	    while(befy[i][j] >= 0 && a[befy[i][j]][j] <= a[i][j])
		befy[i][j] = befy[ befy[i][j] ][j];
	}
	for(int i = n-1; i >= 0; i--){
	    afty[i][j] = i+1;
	    while(afty[i][j] < n && a[afty[i][j]][j] <= a[i][j])
		afty[i][j] = afty[ afty[i][j] ][j];
	}	
    }
    */

    for(int i = 0; i < n; i++){
	for(int j = 0; j < m; j++){
	    befx[i][j] = j-1;
	    while(befx[i][j] >= 0 && a[i][befx[i][j]] <= a[i][j])
		befx[i][j]--;
	}
	for(int j = m-1; j >= 0; j--){
	    aftx[i][j] = j+1;
	    while(aftx[i][j] < m && a[i][aftx[i][j]] <= a[i][j])
		aftx[i][j]++;
	}
    }
    for(int j = 0; j < m; j++){
	for(int i = 0; i < n; i++){
	    befy[i][j] = i-1;
	    while(befy[i][j] >= 0 && a[befy[i][j]][j] <= a[i][j])
		befy[i][j]--;
	}
	for(int i = n-1; i >= 0; i--){
	    afty[i][j] = i+1;
	    while(afty[i][j] < n && a[afty[i][j]][j] <= a[i][j])
		afty[i][j]++;
	}	
    }

    
    ll ans = 0;
    /*
    for(int i = 0; i < n; i++){
	for(int j = 0; j < m; j++){
	    ans+= ok(befy[i][j] + 1, afty[i][j] - 1, befx[i][j] + 1, aftx[i][j] - 1, i, j);
	}
	}*/
    for(int a = 0; a < n; a++){
	for(int b = a; b < n; b++){
	    for(int c = 0; c < m; c++){
		for(int d = c; d < m; d++){
		    ans+= ok(a, b, c, d);
		}
	    }
	}
    }
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...