Submission #266770

# Submission time Handle Problem Language Result Execution time Memory
266770 2020-08-15T12:45:21 Z dennisstar Rectangles (IOI19_rect) C++17
59 / 100
5000 ms 491332 KB
#include <bits/stdc++.h>
#include "rect.h"
#define eb emplace_back
using namespace std;
using tii=tuple<int, int, int>;

int N, M;
vector<tii> H, V;

long long count_rectangles(vector<vector<int>> a) {
	N=a.size(); M=a[0].size();
	vector<vector<int>> l, r, u, d;
	for (int i=0; i<N; i++)
		l.eb(vector<int>(M, -1));
	r=u=d=l;

	for (int i=0; i<N; i++) {
		vector<int> st;
		for (int j=0; j<M; j++) {
			while (st.size()&&a[i][st.back()]<a[i][j]) st.pop_back();
			if (st.size()) H.eb(st.back(), j, i);
			st.eb(j);
		}
		st.clear();
		for (int j=M-1; j>=0; j--) {
			while (st.size()&&a[i][st.back()]<a[i][j]) st.pop_back();
			if (st.size()) H.eb(j, st.back(), i);
			st.eb(j);
		}
		st.clear();
		for (int j=0; j<M; j++) {
			while (st.size()&&a[i][st.back()]<=a[i][j]) st.pop_back();
			if (st.size()) l[i][j]=st.back();
			st.eb(j);
		}
		st.clear();
		for (int j=M-1; j>=0; j--) {
			while (st.size()&&a[i][st.back()]<=a[i][j]) st.pop_back();
			if (st.size()) r[i][j]=st.back();
			st.eb(j);
		}
	}

	for (int j=0; j<M; j++) {
		vector<int> st;
		for (int i=0; i<N; i++) {
			while (st.size()&&a[st.back()][j]<a[i][j]) st.pop_back();
			if (st.size()) V.eb(st.back(), i, j);
			st.eb(i);
		}
		st.clear();
		for (int i=N-1; i>=0; i--) {
			while (st.size()&&a[st.back()][j]<a[i][j]) st.pop_back();
			if (st.size()) V.eb(i, st.back(), j);
			st.eb(i);
		}
		st.clear();
		for (int i=0; i<N; i++) {
			while (st.size()&&a[st.back()][j]<=a[i][j]) st.pop_back();
			if (st.size()) u[i][j]=st.back();
			st.eb(i);
		}
		st.clear();
		for (int i=N-1; i>=0; i--) {
			while (st.size()&&a[st.back()][j]<=a[i][j]) st.pop_back();
			if (st.size()) d[i][j]=st.back();
			st.eb(i);
		}
	}

	sort(H.begin(), H.end());
	H.resize(unique(H.begin(), H.end())-H.begin());
	
	sort(V.begin(), V.end());
	V.resize(unique(V.begin(), V.end())-V.begin());

	vector<tuple<int, int, int, int>> A;
	for (int i=1; i<N-1; i++) for (int j=1; j<M-1; j++) {
		int L=l[i][j], R=r[i][j], U=u[i][j], D=d[i][j];
		if (L==-1||R==-1||U==-1||D==-1) continue;

		int b1=lower_bound(H.begin(), H.end(), tii(L, R, U+1))-H.begin();
		if (b1>=H.size()||tii(L, R, U+1)!=H[b1]) continue;
		b1+=D-U-2;
		if (b1>=H.size()||tii(L, R, D-1)!=H[b1]) continue;

		b1=lower_bound(V.begin(), V.end(), tii(U, D, L+1))-V.begin();
		if (b1>=V.size()||tii(U, D, L+1)!=V[b1]) continue;
		b1+=R-L-2;
		if (b1>=V.size()||tii(U, D, R-1)!=V[b1]) continue;

		A.eb(L, R, U, D);
	}

	sort(A.begin(), A.end());
	return unique(A.begin(), A.end())-A.begin();
}

Compilation message

rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:83:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |   if (b1>=H.size()||tii(L, R, U+1)!=H[b1]) continue;
      |       ~~^~~~~~~~~~
rect.cpp:85:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |   if (b1>=H.size()||tii(L, R, D-1)!=H[b1]) continue;
      |       ~~^~~~~~~~~~
rect.cpp:88:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |   if (b1>=V.size()||tii(U, D, L+1)!=V[b1]) continue;
      |       ~~^~~~~~~~~~
rect.cpp:90:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |   if (b1>=V.size()||tii(U, D, R-1)!=V[b1]) continue;
      |       ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 7 ms 1024 KB Output is correct
18 Correct 7 ms 1024 KB Output is correct
19 Correct 6 ms 1024 KB Output is correct
20 Correct 6 ms 960 KB Output is correct
21 Correct 6 ms 960 KB Output is correct
22 Correct 6 ms 960 KB Output is correct
23 Correct 6 ms 960 KB Output is correct
24 Correct 3 ms 640 KB Output is correct
25 Correct 1 ms 256 KB Output is correct
26 Correct 0 ms 256 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 7 ms 1024 KB Output is correct
18 Correct 7 ms 1024 KB Output is correct
19 Correct 6 ms 1024 KB Output is correct
20 Correct 6 ms 960 KB Output is correct
21 Correct 6 ms 960 KB Output is correct
22 Correct 6 ms 960 KB Output is correct
23 Correct 6 ms 960 KB Output is correct
24 Correct 3 ms 640 KB Output is correct
25 Correct 41 ms 5100 KB Output is correct
26 Correct 41 ms 5092 KB Output is correct
27 Correct 44 ms 5100 KB Output is correct
28 Correct 35 ms 4596 KB Output is correct
29 Correct 41 ms 4724 KB Output is correct
30 Correct 42 ms 4852 KB Output is correct
31 Correct 41 ms 4852 KB Output is correct
32 Correct 40 ms 4852 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 0 ms 256 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 7 ms 1024 KB Output is correct
18 Correct 7 ms 1024 KB Output is correct
19 Correct 6 ms 1024 KB Output is correct
20 Correct 6 ms 960 KB Output is correct
21 Correct 6 ms 960 KB Output is correct
22 Correct 6 ms 960 KB Output is correct
23 Correct 6 ms 960 KB Output is correct
24 Correct 3 ms 640 KB Output is correct
25 Correct 41 ms 5100 KB Output is correct
26 Correct 41 ms 5092 KB Output is correct
27 Correct 44 ms 5100 KB Output is correct
28 Correct 35 ms 4596 KB Output is correct
29 Correct 41 ms 4724 KB Output is correct
30 Correct 42 ms 4852 KB Output is correct
31 Correct 41 ms 4852 KB Output is correct
32 Correct 40 ms 4852 KB Output is correct
33 Correct 266 ms 39872 KB Output is correct
34 Correct 255 ms 39876 KB Output is correct
35 Correct 270 ms 39988 KB Output is correct
36 Correct 218 ms 39876 KB Output is correct
37 Correct 599 ms 51604 KB Output is correct
38 Correct 592 ms 51592 KB Output is correct
39 Correct 599 ms 51888 KB Output is correct
40 Correct 546 ms 49068 KB Output is correct
41 Correct 425 ms 42824 KB Output is correct
42 Correct 477 ms 42824 KB Output is correct
43 Correct 608 ms 42824 KB Output is correct
44 Correct 588 ms 43208 KB Output is correct
45 Correct 281 ms 21976 KB Output is correct
46 Correct 304 ms 21980 KB Output is correct
47 Correct 596 ms 43572 KB Output is correct
48 Correct 592 ms 43956 KB Output is correct
49 Correct 1 ms 256 KB Output is correct
50 Correct 0 ms 256 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 960 KB Output is correct
2 Correct 4 ms 820 KB Output is correct
3 Correct 3 ms 960 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 5 ms 896 KB Output is correct
6 Correct 4 ms 896 KB Output is correct
7 Correct 4 ms 896 KB Output is correct
8 Correct 4 ms 840 KB Output is correct
9 Correct 5 ms 968 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2890 ms 235372 KB Output is correct
3 Execution timed out 5062 ms 491332 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 7 ms 1024 KB Output is correct
18 Correct 7 ms 1024 KB Output is correct
19 Correct 6 ms 1024 KB Output is correct
20 Correct 6 ms 960 KB Output is correct
21 Correct 6 ms 960 KB Output is correct
22 Correct 6 ms 960 KB Output is correct
23 Correct 6 ms 960 KB Output is correct
24 Correct 3 ms 640 KB Output is correct
25 Correct 41 ms 5100 KB Output is correct
26 Correct 41 ms 5092 KB Output is correct
27 Correct 44 ms 5100 KB Output is correct
28 Correct 35 ms 4596 KB Output is correct
29 Correct 41 ms 4724 KB Output is correct
30 Correct 42 ms 4852 KB Output is correct
31 Correct 41 ms 4852 KB Output is correct
32 Correct 40 ms 4852 KB Output is correct
33 Correct 266 ms 39872 KB Output is correct
34 Correct 255 ms 39876 KB Output is correct
35 Correct 270 ms 39988 KB Output is correct
36 Correct 218 ms 39876 KB Output is correct
37 Correct 599 ms 51604 KB Output is correct
38 Correct 592 ms 51592 KB Output is correct
39 Correct 599 ms 51888 KB Output is correct
40 Correct 546 ms 49068 KB Output is correct
41 Correct 425 ms 42824 KB Output is correct
42 Correct 477 ms 42824 KB Output is correct
43 Correct 608 ms 42824 KB Output is correct
44 Correct 588 ms 43208 KB Output is correct
45 Correct 281 ms 21976 KB Output is correct
46 Correct 304 ms 21980 KB Output is correct
47 Correct 596 ms 43572 KB Output is correct
48 Correct 592 ms 43956 KB Output is correct
49 Correct 6 ms 960 KB Output is correct
50 Correct 4 ms 820 KB Output is correct
51 Correct 3 ms 960 KB Output is correct
52 Correct 1 ms 256 KB Output is correct
53 Correct 5 ms 896 KB Output is correct
54 Correct 4 ms 896 KB Output is correct
55 Correct 4 ms 896 KB Output is correct
56 Correct 4 ms 840 KB Output is correct
57 Correct 5 ms 968 KB Output is correct
58 Correct 2 ms 512 KB Output is correct
59 Correct 3 ms 768 KB Output is correct
60 Correct 1 ms 256 KB Output is correct
61 Correct 2890 ms 235372 KB Output is correct
62 Execution timed out 5062 ms 491332 KB Time limit exceeded
63 Halted 0 ms 0 KB -