답안 #400486

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400486 2021-05-08T06:33:31 Z Lawliet 호화 벙커 (IZhO13_burrow) C++17
100 / 100
515 ms 13988 KB
#include <bits/stdc++.h>
 
#define MAX 1010
#define INF 1000000010
 
using namespace std;
 
int n, m, k;
 
int L[MAX];
int R[MAX];
int v[MAX][MAX];
int histogram[MAX];
 
int largestRectangle()
{
	for(int g = 1 ; g <= m ; g++)
	{
		int cur = g - 1;
 
		while(histogram[g] <= histogram[cur]) cur = L[cur];
 
		L[g] = cur;
	}
 
	for(int g = m ; g >= 1 ; g--)
	{
		int cur = g + 1;
 
		while(histogram[g] <= histogram[cur]) cur = R[cur];
 
		R[g] = cur;
	}
 
	int ans = 0;
 
	for(int g = 1 ; g <= m ; g++)
		ans = max(ans , histogram[g]*(R[g] - L[g] - 1));
 
	return ans;
}
 
bool test(int l, int t = 0)
{
	int ans = -1;
 
	memset(histogram , 0 , sizeof(histogram));
	histogram[0] = histogram[m + 1] = -INF;
 
	for(int g = 1 ; g <= n ; g++)
	{
		for(int h = 1 ; h <= m ; h++)
		{
			if(v[g][h] >= l) histogram[h]++;
			else histogram[h] = 0;
		}
 
		ans = max(ans , largestRectangle());
	}
 
	if(t == 1) printf("%d\n",ans);
 
	return ans >= k;
}
 
int bs()
{
	int l = 0, r = INF;
 
	while(l < r)
	{
		int m = (l + r)/2;
		if( l == r - 1 ) m = r;
 
		if( test(m) ) l = m;
		else r = m - 1;
	}
 
	return l;
}
 
void init()
{
	L[0] = 0;
	R[m + 1] = m + 1;
}
 
int main()
{
	scanf("%d %d %d",&n,&m,&k);
 
	init();
 
	for(int g = 1 ; g <= n ; g++)
		for(int h = 1 ; h <= m ; h++)
			scanf("%d",&v[g][h]);
 
	int ans = bs();
 
	printf("%d ",ans);
 
	test(ans , 1);
}

Compilation message

burrow.cpp: In function 'int main()':
burrow.cpp:90:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   90 |  scanf("%d %d %d",&n,&m,&k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~
burrow.cpp:96:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   96 |    scanf("%d",&v[g][h]);
      |    ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 444 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 6 ms 716 KB Output is correct
9 Correct 9 ms 1228 KB Output is correct
10 Correct 24 ms 1376 KB Output is correct
11 Correct 40 ms 1892 KB Output is correct
12 Correct 25 ms 2432 KB Output is correct
13 Correct 31 ms 1088 KB Output is correct
14 Correct 75 ms 2464 KB Output is correct
15 Correct 77 ms 2472 KB Output is correct
16 Correct 76 ms 3032 KB Output is correct
17 Correct 94 ms 2772 KB Output is correct
18 Correct 196 ms 5356 KB Output is correct
19 Correct 237 ms 4904 KB Output is correct
20 Correct 443 ms 9104 KB Output is correct
21 Correct 408 ms 10020 KB Output is correct
22 Correct 498 ms 13924 KB Output is correct
23 Correct 515 ms 13988 KB Output is correct
24 Correct 387 ms 6916 KB Output is correct
25 Correct 397 ms 7020 KB Output is correct