Submission #240901

#TimeUsernameProblemLanguageResultExecution timeMemory
240901zoomswkRectangles (IOI19_rect)C++17
0 / 100
5 ms384 KiB
#include "rect.h"
using namespace std;

int max_in_row[205][205][205]; // max_in_row[i][j][k] = max{a[i][j..k]}
int col_prev_larger[205][205]; // stores prev row
int min_col_prev_larger[205][205][205]; // stores prev row
int col_next_larger[205][205]; // stores next row
int max_col_next_larger[205][205][205];	// stores next row

long long count_rectangles(std::vector<std::vector<int> > a) {
	int n = (int)a.size();
	int m = (int)a[0].size();
	if(n < 3 || m < 3) return 0;
	if(n > 3 || m > 3) return 1;
	for(int i=1; i<n-1; i++){
		for(int j=1; j<m-1; j++){

			max_in_row[i][j][j] = a[i][j];
			for(int k=j+1; k<m-1; k++){
				max_in_row[i][j][k] = max(max_in_row[i][j][k-1], a[i][k]);
			}

			col_prev_larger[i][j] = 1e9;
			for(int k=i-1; k>=0; k--){
				if(a[k][j] > a[i][j]){
					col_prev_larger[i][j] = k;
					break;
				}
			}

			col_next_larger[i][j] = -1;
			for(int k=i+1; k<n; k++){
				if(a[k][j] > a[i][j]){
					col_next_larger[i][j] = k;
					break;
				}
			}

		}
	}
	for(int r=1; r<n-1; r++){
		for(int i=1; i<m-1; i++){
			min_col_prev_larger[r][i][i] = col_prev_larger[r][i];
			for(int j=i+1; j<m-1; j++){
				min_col_prev_larger[r][i][j] = min(min_col_prev_larger[r][i][j-1], col_prev_larger[r][j]);
			}

			max_col_next_larger[r][i][i] = col_next_larger[r][i];
			for(int j=i+1; j<m-1; j++){
				max_col_next_larger[r][i][j] = max(max_col_next_larger[r][i][j-1], col_next_larger[r][j]);
			}
		}
	}
	long long res = 0;
	for(int r=1; r<n-1; r++){
		for(int c=1; c<m-1; c++){
			for(int cc=c; cc<m-1; cc++){
				int max_col_req = -1;
				int min_col_req = 1e9;
				for(int rr=r; rr<n-1; rr++){
					max_col_req = max(max_col_req, max_col_next_larger[rr][c][cc]);
					min_col_req = min(min_col_req, min_col_prev_larger[rr][c][cc]);
					if(min_col_req != r-1) break;
					if(max_in_row[rr][c][cc] >= a[rr][c-1] || max_in_row[rr][c][cc] >= a[rr][cc+1]) break;
					if(max_col_req == rr+1) res++;
				}
			}
		}
	}
	return res;
}
#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...