답안 #1034054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034054 2024-07-25T09:12:11 Z AmirAli_H1 Rectangles (IOI19_rect) C++17
0 / 100
1792 ms 964 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];

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]]);
		}
	}
	
	ll ans = 0;
	for (int l1 = 1; l1 < n - 1; l1++) {
		for (int r1 = l1; r1 < n - 1; r1++) {
			for (int l2 = 1; l2 < m - 1; l2++) {
				for (int r2 = l2; r2 < m - 1; r2++) {
					if (ok(l1, r1, l2, r2)) ans++;
				}
			}
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 964 KB Output is correct
7 Correct 0 ms 860 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Incorrect 1 ms 856 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 964 KB Output is correct
7 Correct 0 ms 860 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Incorrect 1 ms 856 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 964 KB Output is correct
7 Correct 0 ms 860 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Incorrect 1 ms 856 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 964 KB Output is correct
7 Correct 0 ms 860 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Incorrect 1 ms 856 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1792 ms 684 KB Output is correct
2 Correct 1133 ms 852 KB Output is correct
3 Correct 10 ms 600 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 11 ms 708 KB Output is correct
6 Correct 11 ms 600 KB Output is correct
7 Correct 11 ms 604 KB Output is correct
8 Correct 11 ms 600 KB Output is correct
9 Incorrect 11 ms 604 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 964 KB Output is correct
7 Correct 0 ms 860 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Incorrect 1 ms 856 KB Output isn't correct
10 Halted 0 ms 0 KB -