Submission #1034107

# Submission time Handle Problem Language Result Execution time Memory
1034107 2024-07-25T09:49:44 Z AmirAli_H1 Rectangles (IOI19_rect) C++17
0 / 100
90 ms 147860 KB
// In the name of Allah

#include <bits/stdc++.h>
#include "rect.h"
using namespace std;

typedef		long long int			ll;
typedef		long double				ld;
typedef		pair<int, int>			pii;
typedef		pair<ll, ll>			pll;
typedef		complex<ld>				cld;

#define		all(x)					(x).begin(),(x).end()
#define		len(x)					((ll) (x).size())
#define		F						first
#define		S						second
#define		pb						push_back
#define		sep						' '
#define		endl					'\n'
#define		Mp						make_pair
#define		kill(x)					cout << x << '\n', exit(0)
#define		set_dec(x)				cout << fixed << setprecision(x);
#define		file_io(x,y)			freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2500 + 4;

int n, m;
int L1[maxn][maxn], R1[maxn][maxn];
int L2[maxn][maxn], R2[maxn][maxn];
vector<int> ls[maxn][maxn];

bool ok(int l1, int r1, int l2, int r2) {
	for (int j = l2; j <= r2; j++) {
		int i1 = l1 - 1, i2 = r1 + 1;
		if (L1[i2][j] != i1 && R1[i1][j] != i2) return 0;
	}
	for (int i = l1; i <= r1; i++) {
		int j1 = l2 - 1, j2 = r2 + 1;
		if (L2[i][j2] != j1 && R2[i][j1] != j2) return 0;
	}
	return 1;
}

ll count_rectangles(vector<vector<int>> A) {
	n = len(A); m = len(A[0]);
	
	for (int j = 0; j < m; j++) {
		for (int i = 0; i < n; i++) {
			for (L1[i][j] = i - 1; L1[i][j] != -1 && A[i][j] > A[L1[i][j]][j]; L1[i][j] = L1[L1[i][j]][j]);
		}
		for (int i = n - 1; i >= 0; i--) {
			for (R1[i][j] = i + 1; R1[i][j] != n && A[i][j] > A[R1[i][j]][j]; R1[i][j] = R1[R1[i][j]][j]);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			for (L2[i][j] = j - 1; L2[i][j] != -1 && A[i][j] > A[i][L2[i][j]]; L2[i][j] = L2[i][L2[i][j]]);
		}
		for (int j = m - 1; j >= 0; j--) {
			for (R2[i][j] = j + 1; R2[i][j] != m && A[i][j] > A[i][R2[i][j]]; R2[i][j] = R2[i][R2[i][j]]);
		}
	}
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (L1[i][j] != -1 && L1[i][j] + 1 <= i - 1) {
				ls[i][L1[i][j]].pb(j);
			}
			if (R1[i][j] != n && i + 1 <= R1[i][j] && A[i][j] < A[R1[i][j]][j]) {
				ls[i][j].pb(R1[i][j]);
			}
		}
	}
	
	ll ans = 0;
	for (int i = 1; i < n - 1; i++) {
		for (int j = 0; j < m; j++) {
			if (L2[i][j] != -1 && L2[i][j] + 1 <= j - 1) {
				for (int x : ls[i - 1][j - 1]) {
					ans += ok(i, x - 1, L2[i][j] + 1, j - 1);
				}
			}
			if (R2[i][j] != m && j + 1 <= R2[i][j] - 1 && A[i][j] < A[i][R2[i][j]]) {
				for (int x : ls[i - 1][j + 1]) {
					ans += ok(i, x - 1, j + 1, R2[i][j] - 1);
				}
			}
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 90 ms 147524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 90 ms 147524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 90 ms 147524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 90 ms 147524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 89 ms 147860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 147792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 90 ms 147524 KB Output isn't correct
2 Halted 0 ms 0 KB -