답안 #928498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
928498 2024-02-16T13:29:07 Z knon0501 Rectangles (IOI19_rect) C++14
50 / 100
5000 ms 238172 KB
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> b[2505][2505];

vector<vector<int>> aa;

int f(int i,int j,int x,int y){
	int cnt1 = 0;
	int cnt2 = 0;
	
	for(int k=i ; k<=j ; k++){
		if(aa[x][k]<aa[y][k])
			cnt1++;
		if(aa[x][k]>aa[y][k])
			cnt2++;
	}
	if(cnt1==j-i+1)return 1;
	if(cnt2==j-i+1)return -1;
	return 0;
}

long long count_rectangles(std::vector<std::vector<int> > a) {
	aa=a;
	int n = a.size();
	int m = a[0].size();

	for(int i=1 ; i<n-1 ; i++){
		stack<int> S;

		for(int j=0 ; j<m ; j++){
			bool flag = true;
			while(!S.empty() && a[i][S.top()] <=  a[i][j]){
				int x = S.top(); 
				
				
				if(x +1 <j && flag)
					b[x+1][j-1].push_back(i);
				if(a[i][S.top()]==a[i][j])flag=false;
				S.pop();
				
			}
			if(!S.empty() && flag){
				int x = S.top();
				if(x+1<j)
					b[x+1][j-1].push_back(i);
			}
			S.push(j);
		}
	}
	long long ans = 0;
	for(int i=1 ; i<m ; i++){
		for(int j=i ; j<m ; j++){
			vector<vector<int>> c;
			int prv=-1;
			
			for(int x: b[i][j]){
			//	cout<<i<<" "<<j<<" "<<x<<endl;
				if(prv+1<x)
					c.push_back({x});
				else
					c.back().push_back(x);
				prv=x;
			}

			for(auto d: c){
				stack<int> S;
			
				d.push_back(d.back()+1);
				d.push_back(d[0]-1);
				
				sort(d.begin(),d.end());
			
				for(auto x: d){
					bool flag = true;
					
					while(!S.empty() && f(i,j,S.top(),x)>=0){
						int k = S.top(); S.pop();
						
						if(k +1 <x && flag){
							bool flag = true;
						for(int l = k+1 ; l<x ; l++)
							if(f(i,j,l,x)<=0)flag = false;
						ans+=flag;
							
						}
						if(f(i,j,k,x)==0){
				
							flag=false;
						}
					}
					if(!S.empty() && S.top()+1<x && flag){
						bool flag = true;
						for(int l = S.top()+1 ; l<x ; l++)
							if(f(i,j,l,x)<=0)flag = false;
						ans+=flag;
					}
					S.push(x);
				}
			}
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 147540 KB Output is correct
2 Correct 34 ms 147804 KB Output is correct
3 Correct 33 ms 147792 KB Output is correct
4 Correct 36 ms 147800 KB Output is correct
5 Correct 34 ms 147804 KB Output is correct
6 Correct 33 ms 147556 KB Output is correct
7 Correct 34 ms 147804 KB Output is correct
8 Correct 34 ms 147604 KB Output is correct
9 Correct 38 ms 147540 KB Output is correct
10 Correct 39 ms 147792 KB Output is correct
11 Correct 34 ms 147792 KB Output is correct
12 Correct 33 ms 147800 KB Output is correct
13 Correct 33 ms 147548 KB Output is correct
14 Correct 34 ms 147548 KB Output is correct
15 Correct 34 ms 147568 KB Output is correct
16 Correct 33 ms 147536 KB Output is correct
17 Correct 34 ms 147620 KB Output is correct
18 Correct 35 ms 147548 KB Output is correct
19 Correct 34 ms 147788 KB Output is correct
20 Correct 35 ms 147804 KB Output is correct
21 Correct 35 ms 147768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 147540 KB Output is correct
2 Correct 34 ms 147804 KB Output is correct
3 Correct 33 ms 147792 KB Output is correct
4 Correct 36 ms 147800 KB Output is correct
5 Correct 34 ms 147804 KB Output is correct
6 Correct 33 ms 147556 KB Output is correct
7 Correct 34 ms 147804 KB Output is correct
8 Correct 34 ms 147604 KB Output is correct
9 Correct 38 ms 147540 KB Output is correct
10 Correct 39 ms 147792 KB Output is correct
11 Correct 34 ms 147792 KB Output is correct
12 Correct 33 ms 147800 KB Output is correct
13 Correct 33 ms 147548 KB Output is correct
14 Correct 34 ms 147548 KB Output is correct
15 Correct 34 ms 147568 KB Output is correct
16 Correct 33 ms 147536 KB Output is correct
17 Correct 34 ms 147620 KB Output is correct
18 Correct 35 ms 147548 KB Output is correct
19 Correct 34 ms 147788 KB Output is correct
20 Correct 35 ms 147804 KB Output is correct
21 Correct 35 ms 147768 KB Output is correct
22 Correct 38 ms 147824 KB Output is correct
23 Correct 39 ms 147788 KB Output is correct
24 Correct 42 ms 147796 KB Output is correct
25 Correct 34 ms 147796 KB Output is correct
26 Correct 37 ms 147800 KB Output is correct
27 Correct 35 ms 147764 KB Output is correct
28 Correct 35 ms 147804 KB Output is correct
29 Correct 35 ms 147676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 147540 KB Output is correct
2 Correct 34 ms 147804 KB Output is correct
3 Correct 33 ms 147792 KB Output is correct
4 Correct 36 ms 147800 KB Output is correct
5 Correct 34 ms 147804 KB Output is correct
6 Correct 33 ms 147556 KB Output is correct
7 Correct 34 ms 147804 KB Output is correct
8 Correct 34 ms 147604 KB Output is correct
9 Correct 38 ms 147540 KB Output is correct
10 Correct 39 ms 147792 KB Output is correct
11 Correct 34 ms 147792 KB Output is correct
12 Correct 33 ms 147800 KB Output is correct
13 Correct 33 ms 147548 KB Output is correct
14 Correct 34 ms 147548 KB Output is correct
15 Correct 34 ms 147568 KB Output is correct
16 Correct 33 ms 147536 KB Output is correct
17 Correct 38 ms 147824 KB Output is correct
18 Correct 39 ms 147788 KB Output is correct
19 Correct 42 ms 147796 KB Output is correct
20 Correct 34 ms 147796 KB Output is correct
21 Correct 37 ms 147800 KB Output is correct
22 Correct 35 ms 147764 KB Output is correct
23 Correct 35 ms 147804 KB Output is correct
24 Correct 35 ms 147676 KB Output is correct
25 Correct 34 ms 147620 KB Output is correct
26 Correct 35 ms 147548 KB Output is correct
27 Correct 34 ms 147788 KB Output is correct
28 Correct 35 ms 147804 KB Output is correct
29 Correct 35 ms 147768 KB Output is correct
30 Correct 210 ms 148708 KB Output is correct
31 Correct 205 ms 148704 KB Output is correct
32 Correct 206 ms 148688 KB Output is correct
33 Correct 40 ms 148256 KB Output is correct
34 Correct 45 ms 148564 KB Output is correct
35 Correct 46 ms 148816 KB Output is correct
36 Correct 45 ms 148792 KB Output is correct
37 Correct 45 ms 148828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 147540 KB Output is correct
2 Correct 34 ms 147804 KB Output is correct
3 Correct 33 ms 147792 KB Output is correct
4 Correct 36 ms 147800 KB Output is correct
5 Correct 34 ms 147804 KB Output is correct
6 Correct 33 ms 147556 KB Output is correct
7 Correct 34 ms 147804 KB Output is correct
8 Correct 34 ms 147604 KB Output is correct
9 Correct 38 ms 147540 KB Output is correct
10 Correct 39 ms 147792 KB Output is correct
11 Correct 34 ms 147792 KB Output is correct
12 Correct 33 ms 147800 KB Output is correct
13 Correct 33 ms 147548 KB Output is correct
14 Correct 34 ms 147548 KB Output is correct
15 Correct 34 ms 147568 KB Output is correct
16 Correct 33 ms 147536 KB Output is correct
17 Correct 38 ms 147824 KB Output is correct
18 Correct 39 ms 147788 KB Output is correct
19 Correct 42 ms 147796 KB Output is correct
20 Correct 34 ms 147796 KB Output is correct
21 Correct 37 ms 147800 KB Output is correct
22 Correct 35 ms 147764 KB Output is correct
23 Correct 35 ms 147804 KB Output is correct
24 Correct 35 ms 147676 KB Output is correct
25 Correct 210 ms 148708 KB Output is correct
26 Correct 205 ms 148704 KB Output is correct
27 Correct 206 ms 148688 KB Output is correct
28 Correct 40 ms 148256 KB Output is correct
29 Correct 45 ms 148564 KB Output is correct
30 Correct 46 ms 148816 KB Output is correct
31 Correct 45 ms 148792 KB Output is correct
32 Correct 45 ms 148828 KB Output is correct
33 Correct 34 ms 147620 KB Output is correct
34 Correct 35 ms 147548 KB Output is correct
35 Correct 34 ms 147788 KB Output is correct
36 Correct 35 ms 147804 KB Output is correct
37 Correct 35 ms 147768 KB Output is correct
38 Correct 210 ms 164516 KB Output is correct
39 Correct 201 ms 164288 KB Output is correct
40 Correct 234 ms 164376 KB Output is correct
41 Correct 230 ms 164180 KB Output is correct
42 Execution timed out 5039 ms 159648 KB Time limit exceeded
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 148000 KB Output is correct
2 Correct 45 ms 147804 KB Output is correct
3 Correct 43 ms 147780 KB Output is correct
4 Correct 33 ms 147548 KB Output is correct
5 Correct 43 ms 147792 KB Output is correct
6 Correct 44 ms 147800 KB Output is correct
7 Correct 48 ms 147796 KB Output is correct
8 Correct 43 ms 147792 KB Output is correct
9 Correct 43 ms 147800 KB Output is correct
10 Correct 42 ms 147804 KB Output is correct
11 Correct 41 ms 147792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 147620 KB Output is correct
2 Correct 35 ms 147548 KB Output is correct
3 Correct 34 ms 147788 KB Output is correct
4 Correct 35 ms 147804 KB Output is correct
5 Correct 35 ms 147768 KB Output is correct
6 Correct 34 ms 147548 KB Output is correct
7 Correct 274 ms 188068 KB Output is correct
8 Correct 574 ms 237356 KB Output is correct
9 Correct 568 ms 237812 KB Output is correct
10 Correct 584 ms 238172 KB Output is correct
11 Correct 101 ms 186704 KB Output is correct
12 Correct 139 ms 222588 KB Output is correct
13 Correct 145 ms 227020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 147540 KB Output is correct
2 Correct 34 ms 147804 KB Output is correct
3 Correct 33 ms 147792 KB Output is correct
4 Correct 36 ms 147800 KB Output is correct
5 Correct 34 ms 147804 KB Output is correct
6 Correct 33 ms 147556 KB Output is correct
7 Correct 34 ms 147804 KB Output is correct
8 Correct 34 ms 147604 KB Output is correct
9 Correct 38 ms 147540 KB Output is correct
10 Correct 39 ms 147792 KB Output is correct
11 Correct 34 ms 147792 KB Output is correct
12 Correct 33 ms 147800 KB Output is correct
13 Correct 33 ms 147548 KB Output is correct
14 Correct 34 ms 147548 KB Output is correct
15 Correct 34 ms 147568 KB Output is correct
16 Correct 33 ms 147536 KB Output is correct
17 Correct 38 ms 147824 KB Output is correct
18 Correct 39 ms 147788 KB Output is correct
19 Correct 42 ms 147796 KB Output is correct
20 Correct 34 ms 147796 KB Output is correct
21 Correct 37 ms 147800 KB Output is correct
22 Correct 35 ms 147764 KB Output is correct
23 Correct 35 ms 147804 KB Output is correct
24 Correct 35 ms 147676 KB Output is correct
25 Correct 210 ms 148708 KB Output is correct
26 Correct 205 ms 148704 KB Output is correct
27 Correct 206 ms 148688 KB Output is correct
28 Correct 40 ms 148256 KB Output is correct
29 Correct 45 ms 148564 KB Output is correct
30 Correct 46 ms 148816 KB Output is correct
31 Correct 45 ms 148792 KB Output is correct
32 Correct 45 ms 148828 KB Output is correct
33 Correct 210 ms 164516 KB Output is correct
34 Correct 201 ms 164288 KB Output is correct
35 Correct 234 ms 164376 KB Output is correct
36 Correct 230 ms 164180 KB Output is correct
37 Execution timed out 5039 ms 159648 KB Time limit exceeded
38 Halted 0 ms 0 KB -