Submission #794757

#TimeUsernameProblemLanguageResultExecution timeMemory
794757APROHACKRectangles (IOI19_rect)C++17
10 / 100
28 ms404 KiB
#include "rect.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
using namespace std;
vector<vector<int>>matrix;


long long count_rectangles(std::vector<std::vector<int> > a) {
	int N, M;
	N = a.size();
	M = a[0].size();
	matrix = a;
	bool all1 = true;
	for(auto i : matrix){
		for(auto j:i){
			if(j != 0 and j != 1)all1 = false;
		}
	}
	if(!all1){
	ll ans = 0;
		for(int i = 1 ; i < N-1 ; i ++){
			for(int j = 1 ; j < M-1 ; j ++){
				for(int ii = i ; ii < N-1 ; ii++){
					for(int jj = j ; jj < M-1 ; jj++){
						bool valid = true;
						for(int x = i ; x <= ii ; x ++){
							for(int pp = j ; pp <= jj ; pp ++){
								int val = matrix[x][pp];
								if(!(val < matrix[x][j-1] and val < matrix[x][jj+1] and val < matrix[i-1][pp] and val < matrix[ii +1][pp])){
									pp = jj +1;
									x = ii + 1;
									valid = false;
								}
							}
						}
						if(valid)ans ++;
					}
				}
			}
		}
		
		return ans;
	}else{
		ll ans = 0;
		auto skip = a;
		for(int i = 0 ; i< N ; i ++){
			for(int j = 0 ; j < M ; j ++){
				skip[i][j] = j;
			}
		}
		for(int i = 1 ; i < N-1 ; i ++){
			for(int j = 1 ; j < M-1 ; j ++){
				j = skip[i][j];
				if(matrix[i][j] == 1 or matrix[i-1][j] != 1 or matrix[i][j-1] != 1)continue;
				int bottom = i, r = j;
				bool damaged = false;
				for(; r < M-1 ; r++){
					if(matrix[i-1][r] != 1){
						damaged = true;
						break;
					}else if(matrix[i][r+1] == 1){
						break;
					}
				}
				if(damaged){
					j = r;
					continue;
				}
				// j - r
				bottom = i+1;
				for(; bottom < N ; bottom ++){
					bool todos0 = true;
					bool todos1 = true;
					for(int k = j ; k <= r ; k ++){
						if(matrix[bottom][k] == 1){
							todos0 = false;
						}else{
							todos1 = false;
						}
					}
					if(todos0){
						if(matrix[bottom][j-1] != 1 or matrix[bottom][r+1] != 1)todos0 = false;
					}
					if(todos1){
						ans ++ ;
						break;
					}
					if(!todos1 and !todos0)break;
				}
				for(int row = i ; row <= bottom ; row ++){
					for (int col = j; col <= r ; col ++){
						skip[row][col] = r + 1;
					}
				}
			}
		}
		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...