QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#663115#2672. RectanglesDimash#13 282ms212492kbC++172.3kb2024-10-21 13:21:562024-10-21 13:21:59

Judging History

你现在查看的是最新测评结果

  • [2024-10-21 13:21:59]
  • 评测
  • 测评结果:13
  • 用时:282ms
  • 内存:212492kb
  • [2024-10-21 13:21:56]
  • 提交

answer

#include "rect.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 2500 + 12;
int n, m, a[N][N], u[N][N], d[N][N], l[N][N], r[N][N], s[N][N];
void prec() {
	for(int i = 1; i <= n; i++) {
		vector<int> st;
		for(int j = 1; j <= m; j++) {
			while(!st.empty() && a[i][st.back()] <= a[i][j]) {
				st.pop_back();
			}
			l[i][j] = (st.empty() ? 0 : st.back());
			st.push_back(j);
		}
		st.clear();
		for(int j = m; j >= 1; j--) {
			while(!st.empty() && a[i][st.back()] <= a[i][j]) {
				st.pop_back();
			}
			r[i][j] = (st.empty() ? m + 1 : st.back());
			st.push_back(j);
		}
	}

	for(int j = 1; j <= m; j++) {
		vector<int> st;
		for(int i = 1; i <= n; i++) {
			while(!st.empty() && a[st.back()][j] <= a[i][j]) {
				st.pop_back();
			}
			u[i][j] = (st.empty() ? 0 : st.back());
			st.push_back(i);
		}
		st.clear();
		for(int i = n; i >= 1; i--) {
			while(!st.empty() && a[st.back()][j] <= a[i][j]) {
				st.pop_back();
			}
			d[i][j] = (st.empty() ? n + 1 : st.back());
			st.push_back(i);
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
		}
	}
}
int get(int x, int y, int x1, int y1) {
	return (s[x1][y1] - s[x1][y - 1] - s[x - 1][y1] + s[x - 1][y - 1]);
}
bool check(int x, int y, int x1, int y1) {
	return (get(x, y, x1, y1) == 0);
}
bool check1(int x, int y, int x1, int y1) {
	int s = get(x, y, x1, y1);
	return (s == (x1 - x + 1) * (y1 - y + 1));
}
ll count_rectangles(vector<vector<int> > _A) {
	n = (int)_A.size();
	m = (int)_A[0].size();
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			a[i][j] = _A[i - 1][j - 1];
		}
	}
	prec();
	ll res = 0;
	for(int i = 2; i < n; i++) {
		for(int j = 2; j < m; j++) {
			if(!a[i][j]) {
				int y = l[i][j] + 1, x = u[i][j] + 1;
				if(x <= 1|| y <= 1) continue;
				// cout << x << ' ' << y << ' ' << i << ' ' << j << '\n';
				if(check(x, y, i, j)) {
					if(!check1(i + 1, y, i + 1, j)) {
						continue;
					}
					if(!check1(x - 1, y, x - 1, j)) {
						continue;
					}
					if(!check1(x, y - 1, i, y - 1)) {
						continue;
					}
					if(!check1(x, j + 1, i, j + 1)) {
						continue;
					}
					res++;
				}
			}
		}
	}
	return res;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 14200kb

input:

8d9a74d5-4c4b-4437-9c49-114beaeb8f1a
30 30
3996 3689 3664 3657 3646 3630 3621 3619 3609 3604 3601 3598 3584 3581 3574 3561 3554 3543 3537 3531 3522 3519 3505 3500 3498 3492 3476 3467 3460 3994
3993 3458 3451 3440 3431 3420 3395 3346 3333 3282 3268 3261 3241 3204 3168 3121 3103 3083 3076 2923 2872 28...

output:

907404fa-efbb-4a2c-83b8-4c377409c80c
OK
0

result:

wrong answer 3rd lines differ - expected: '784', found: '0'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #53:

score: 0
Wrong Answer
time: 0ms
memory: 14128kb

input:

8d9a74d5-4c4b-4437-9c49-114beaeb8f1a
3 2500
3999533 3994407 3992243 3991052 3990430 3988819 3987546 3985557 3983808 3983398 3982565 3981632 3981437 3979888 3979428 3978697 3978033 3975044 3973166 3972565 3971499 3970538 3969576 3969014 3968513 3968337 3966950 3965168 3964140 3963957 3962080 3961829 ...

output:

907404fa-efbb-4a2c-83b8-4c377409c80c
OK
0

result:

wrong answer 3rd lines differ - expected: '2498', found: '0'

Subtask #6:

score: 13
Accepted

Test #64:

score: 13
Accepted
time: 3ms
memory: 16108kb

input:

8d9a74d5-4c4b-4437-9c49-114beaeb8f1a
10 10
1 1 0 0 1 0 0 1 0 0
0 1 0 0 1 0 0 1 1 0
0 1 0 0 0 0 0 1 1 0
1 0 0 0 1 0 0 0 1 1
1 0 1 1 0 0 1 1 0 1
0 0 1 0 0 0 1 1 0 0
1 0 1 1 1 1 1 1 1 0
1 0 0 0 1 1 1 1 0 0
1 0 0 1 1 0 1 0 1 1
0 0 0 0 0 1 0 1 1 0

output:

907404fa-efbb-4a2c-83b8-4c377409c80c
OK
2

result:

ok 3 lines

Test #65:

score: 13
Accepted
time: 109ms
memory: 115904kb

input:

8d9a74d5-4c4b-4437-9c49-114beaeb8f1a
1234 2321
0 0 0 1 0 0 0 1 0 0 0 1 1 1 0 1 1 1 0 0 0 0 1 1 1 1 0 1 0 0 0 1 0 0 0 1 1 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 1 0 0 0 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 1 0 1 1 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 0 1 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 1 0 1 1 0 1 0 1 1 1 1 0 1 1...

output:

907404fa-efbb-4a2c-83b8-4c377409c80c
OK
116238

result:

ok 3 lines

Test #66:

score: 13
Accepted
time: 278ms
memory: 211916kb

input:

8d9a74d5-4c4b-4437-9c49-114beaeb8f1a
2487 2500
1 1 0 1 1 0 0 0 1 1 1 1 1 1 1 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 0 1 0 1 0 1 1 1 0 0 1 1 1 1 0 1 1 1 0 1 1 1 0 1 0 0 1 1 0 1 1 0 1 0 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 1 1 1 0 1 1 0 1 0 1 1 1 0 1...

output:

907404fa-efbb-4a2c-83b8-4c377409c80c
OK
250951

result:

ok 3 lines

Test #67:

score: 13
Accepted
time: 269ms
memory: 212472kb

input:

8d9a74d5-4c4b-4437-9c49-114beaeb8f1a
2500 2499
0 1 1 1 1 0 1 0 1 0 0 0 0 0 0 1 0 1 1 0 0 0 0 1 0 0 1 0 1 1 1 1 0 1 0 1 1 1 1 0 1 0 0 0 1 0 1 1 0 0 0 1 1 1 0 1 0 1 0 1 0 1 0 0 0 1 1 0 1 0 1 1 0 0 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 0 0 1 0 1 0 1 0 1 1 0 0 0 1 1 0 0 0 1 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0...

output:

907404fa-efbb-4a2c-83b8-4c377409c80c
OK
251914

result:

ok 3 lines

Test #68:

score: 13
Accepted
time: 282ms
memory: 212492kb

input:

8d9a74d5-4c4b-4437-9c49-114beaeb8f1a
2500 2500
1 0 1 0 1 0 0 0 1 1 1 1 1 0 1 1 1 0 0 0 1 1 1 0 1 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 1 0 1 1 0 0 1 0 0 1 0 0 1 1 0 0 0 0 0 1 1 0 1 0 1 1 0 1 1 1 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 1 0 1 0 1 1 1 1 0 1 1 1 0 1 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0 0 0...

output:

907404fa-efbb-4a2c-83b8-4c377409c80c
OK
252270

result:

ok 3 lines

Test #69:

score: 13
Accepted
time: 59ms
memory: 118896kb

input:

8d9a74d5-4c4b-4437-9c49-114beaeb8f1a
1234 2500
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

907404fa-efbb-4a2c-83b8-4c377409c80c
OK
0

result:

ok 3 lines

Test #70:

score: 13
Accepted
time: 112ms
memory: 208324kb

input:

8d9a74d5-4c4b-4437-9c49-114beaeb8f1a
2500 2345
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

907404fa-efbb-4a2c-83b8-4c377409c80c
OK
0

result:

ok 3 lines

Test #71:

score: 13
Accepted
time: 121ms
memory: 212088kb

input:

8d9a74d5-4c4b-4437-9c49-114beaeb8f1a
2500 2500
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

907404fa-efbb-4a2c-83b8-4c377409c80c
OK
0

result:

ok 3 lines

Subtask #7:

score: 0
Skipped

Dependency #1:

0%