| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 824610 | tomruk | Rectangles (IOI19_rect) | C++17 | 0 ms | 0 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "rect.h"
#include <bits/stdc++.h>
#define N 705
using namespace std;
int dwn[N][N][N];
int rght[N][N][N];
long long count_rectangles(vector<vector<int>> a){
	long long ans = 0;
	int n = a.size();
	int m = a[0].size();
	for(int i = n-1;i>=0;i--){
		for(int j = 0;j<m-1;j++){
			int maxi = a[i][j+1];
			for(int c = j+2;c<m && maxi < a[i][j];c++){
				if(maxi >= a[i][c])
					continue;
				dwn[i][j][c] = 1;
				dwn[i][j][c] += dwn[i+1][j][c];
				maxi = a[i][c];
			}
		}
	}
	for(int i = m-1;i>=0;i--){
		for(int j = 0;j<n-1;j++){
			int maxi = a[j+1][i];
			for(int c = j+2;c<n && maxi < a[j][i];c++){
				if(maxi >= a[c][i])
					continue;
				rght[j][i][c] = 1;
				rght[j][i][c] += rght[j][i + 1][c];
				maxi = a[c][i];
			}
		}
	}
	for(int i = 1;i<n-1;i++){
		for(int j = 0;j<m;j++){
			for(int c = j+2;c<m;c++){
				for(int d = i + 1;d <= i + dwn[i][j][c];d++){
					ans += (j + 1 + rght[i-1][j+1][d]) >= c; 
				}
			}
		}
	}
	return ans;
}
