Submission #349210

# Submission time Handle Problem Language Result Execution time Memory
349210 2021-01-17T05:25:54 Z tengiz05 Rectangles (IOI19_rect) C++17
50 / 100
1991 ms 100844 KB
#include "rect.h"
#ifndef EVAL
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2505;
int n, m, dp[N][N];
vector<vector<int>> a;
inline bool check(int r1, int c1, int r2, int c2){
	for(int i=r1;i<=r2;i++){
		for(int j=c1;j<=c2;j++){
			int t = min(min(a[i][c1-1], a[i][c2+1]), min(a[r1-1][j], a[r2+1][j]));
			if(a[i][j] >= t)return false;
		}
	}return true;
}

int get(int x1,int y1,int x2,int y2){
	int res = dp[x2][y2];
	if(x1&&y1)res += dp[x1-1][y1-1];
	if(x1)res -= dp[x1-1][y2];
	if(y1)res -= dp[x2][y1-1];
	return res;
}


ll count_rectangles(vector<vector<int>> a){
	::a = a;
	n = a.size();
	m = a[0].size();
	ll ans = 0;
	if(n*m <= 50000){
		for(int i=1;i<n-1;i++){
			for(int j=1;j<m-1;j++){
				for(int I=i;I<n-1;I++){
					for(int J=j;J<m-1;J++){
						ans += check(i,j,I,J);
					}
				}
			}
		}return ans;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			dp[i][j] = a[i][j];
			if(j)dp[i][j] += dp[i][j-1];
		}for(int j=0;j<m;j++){
			if(i)dp[i][j] += dp[i-1][j];
		}
	}
	for(int i=1;i<n-1;i++){
		for(int j=1;j<m-1;j++){
			if(a[i][j]==1)continue;
			if(a[i][j-1]!=1 || a[i-1][j]!=1)continue;
			int x = i, y = j;
			while(x+1 < n && a[x+1][j]==0)x++;
			while(y+1 < m && a[i][y+1]==0)y++;
			if(get(i,j,x,y) == 0 && get(i-1,j,i-1,y) == y-j+1 && get(x+1,j,x+1,y) == y-j+1 && get(i,j-1,x,j-1) == x-i+1 && get(i,y+1,x,y+1) == x-i+1)ans++;
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 52 ms 492 KB Output is correct
18 Correct 50 ms 456 KB Output is correct
19 Correct 51 ms 364 KB Output is correct
20 Correct 41 ms 492 KB Output is correct
21 Correct 45 ms 492 KB Output is correct
22 Correct 42 ms 364 KB Output is correct
23 Correct 43 ms 364 KB Output is correct
24 Correct 11 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 0 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 52 ms 492 KB Output is correct
18 Correct 50 ms 456 KB Output is correct
19 Correct 51 ms 364 KB Output is correct
20 Correct 41 ms 492 KB Output is correct
21 Correct 45 ms 492 KB Output is correct
22 Correct 42 ms 364 KB Output is correct
23 Correct 43 ms 364 KB Output is correct
24 Correct 11 ms 364 KB Output is correct
25 Correct 1991 ms 876 KB Output is correct
26 Correct 1937 ms 868 KB Output is correct
27 Correct 1983 ms 748 KB Output is correct
28 Correct 1560 ms 876 KB Output is correct
29 Correct 1679 ms 876 KB Output is correct
30 Correct 1681 ms 868 KB Output is correct
31 Correct 1661 ms 876 KB Output is correct
32 Correct 1630 ms 856 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 0 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 52 ms 492 KB Output is correct
18 Correct 50 ms 456 KB Output is correct
19 Correct 51 ms 364 KB Output is correct
20 Correct 41 ms 492 KB Output is correct
21 Correct 45 ms 492 KB Output is correct
22 Correct 42 ms 364 KB Output is correct
23 Correct 43 ms 364 KB Output is correct
24 Correct 11 ms 364 KB Output is correct
25 Correct 1991 ms 876 KB Output is correct
26 Correct 1937 ms 868 KB Output is correct
27 Correct 1983 ms 748 KB Output is correct
28 Correct 1560 ms 876 KB Output is correct
29 Correct 1679 ms 876 KB Output is correct
30 Correct 1681 ms 868 KB Output is correct
31 Correct 1661 ms 876 KB Output is correct
32 Correct 1630 ms 856 KB Output is correct
33 Incorrect 22 ms 10860 KB Output isn't correct
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 364 KB Output is correct
2 Correct 12 ms 364 KB Output is correct
3 Correct 14 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 15 ms 364 KB Output is correct
6 Correct 17 ms 492 KB Output is correct
7 Correct 15 ms 364 KB Output is correct
8 Correct 16 ms 364 KB Output is correct
9 Correct 15 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 96 ms 46316 KB Output is correct
3 Correct 201 ms 98028 KB Output is correct
4 Correct 199 ms 98540 KB Output is correct
5 Correct 205 ms 98540 KB Output is correct
6 Correct 68 ms 48748 KB Output is correct
7 Correct 131 ms 96236 KB Output is correct
8 Correct 134 ms 100844 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 52 ms 492 KB Output is correct
18 Correct 50 ms 456 KB Output is correct
19 Correct 51 ms 364 KB Output is correct
20 Correct 41 ms 492 KB Output is correct
21 Correct 45 ms 492 KB Output is correct
22 Correct 42 ms 364 KB Output is correct
23 Correct 43 ms 364 KB Output is correct
24 Correct 11 ms 364 KB Output is correct
25 Correct 1991 ms 876 KB Output is correct
26 Correct 1937 ms 868 KB Output is correct
27 Correct 1983 ms 748 KB Output is correct
28 Correct 1560 ms 876 KB Output is correct
29 Correct 1679 ms 876 KB Output is correct
30 Correct 1681 ms 868 KB Output is correct
31 Correct 1661 ms 876 KB Output is correct
32 Correct 1630 ms 856 KB Output is correct
33 Incorrect 22 ms 10860 KB Output isn't correct
34 Halted 0 ms 0 KB -