Submission #168404

#TimeUsernameProblemLanguageResultExecution timeMemory
168404abilLuxury burrow (IZhO13_burrow)C++14
100 / 100
727 ms14072 KiB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define pb push_bacak
#define mk make_pair
#define all(s) s.begin(),s.end()
//#define int long long

using namespace std;

const int N = (1e6 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);

int a[1012][1012], b[1012], n, m, l[1012], r[1012];

int check(int x){
	for(int i = 1;i <= m; i++){
		b[i] = 0;
	}
	int res = 0;
	stack <int > st;
	for(int i = 1;i <= n; i++){
		for(int j = 1;j <= m; j++){
			if(a[i][j] >= x){
				b[j]++;
			}
			else{
				b[j] = 0;
			}
		}
		for(int j = 1;j <= m; j++){
			while(!st.empty() && b[st.top()] >= b[j]){
				st.pop();
			}
			if(!st.empty()){
				l[j] = st.top() + 1;
			}
			else{
				l[j] = 1;
			}
			st.push(j);
		}
		while(!st.empty()){
			st.pop();
		}
		for(int j = m;j >= 1; j--){
			while(!st.empty() && b[st.top()] >= b[j]){
				st.pop();
			}
			if(!st.empty()){
				r[j] = st.top() - 1;
			}
			else{
				r[j] = m;
			}
			st.push(j);
		}
		while(!st.empty()){
			st.pop();
		}
		for(int j = 1;j <= m; j++){
			res = max(res, (r[j] - l[j] + 1) * b[j]);
		}
	}
	return res;
}

main()
{
	int k;
	scanf("%d%d%d", &n, &m, &k);
	for(int i = 1;i <= n; i++){
		for(int j = 1;j <= m; j++){
			scanf("%d", &a[i][j]);
		}
	}
	//cout << check(2);
	int l = 0, r = INF;
	while(r - l > 1){
		int mid = (r + l) >> 1;
		if(check(mid) >= k){
			l = mid;
		}
		else{
			r = mid;
		}
	}
	if(check(r) >= k){
		l = r;
	}
	
	printf("%d %d", l, check(l));
}

Compilation message (stderr)

burrow.cpp:70:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
burrow.cpp: In function 'int main()':
burrow.cpp:73:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n, &m, &k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
burrow.cpp:76:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &a[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...