제출 #622360

#제출 시각아이디문제언어결과실행 시간메모리
622360JomnoiRectangles (IOI19_rect)C++17
15 / 100
5092 ms120012 KiB
#include <bits/stdc++.h>
#include "rect.h"
using namespace std;

const int MAX_W = 205;
const int MAX_N = 2505;

int N, M;
int maxRow[MAX_W][MAX_W][MAX_W];
int maxCol[MAX_W][MAX_W][MAX_W];

long long count_rectangles(vector <vector <int>> a) {
	N = a.size(), M = a[0].size();
	if(min(N, M) < 3) {
		return 0;
	}

	for(int r = 0; r < N; r++) {
		for(int c = 0; c < M; c++) {
			maxRow[r][c][c] = a[r][c];
		}
		for(int sz = 1; sz < M; sz++) {
			for(int c1 = 0, c2 = sz; c2 < M; c1++, c2++) {
				maxRow[r][c1][c2] = max(maxRow[r][c1 + 1][c2], maxRow[r][c1][c2 - 1]);
			}
		}
	}
	for(int c = 0; c < M; c++) {
		for(int r = 0; r < N; r++) {
			maxCol[c][r][r] = a[r][c];
		}
		for(int sz = 1; sz < N; sz++) {
			for(int r1 = 0, r2 = sz; r2 < N; r1++, r2++) {
				maxCol[c][r1][r2] = max(maxCol[c][r1 + 1][r2], maxCol[c][r1][r2 - 1]);
			}
		}
	}

	int ans = 0;
	for(int r1 = 1; r1 < N - 1; r1++) {
		for(int r2 = r1; r2 < N - 1; r2++) {
			for(int c1 = 1; c1 < M - 1; c1++) {
				bool okCol = true;
				for(int c2 = c1; c2 < M - 1; c2++) {
					okCol &= (min(a[r1 - 1][c2], a[r2 + 1][c2]) > maxCol[c2][r1][r2]);
					
					bool okRow = true;
					for(int r3 = r1; r3 <= r2; r3++) {
						okRow &= (min(a[r3][c1 - 1], a[r3][c2 + 1]) > maxRow[r3][c1][c2]);
					}

					ans += (okCol == true and okRow == true);
				}
			}	
		}
	}
	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...