답안 #42319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
42319 2018-02-26T02:09:57 Z wzy 호화 벙커 (IZhO13_burrow) C++11
100 / 100
698 ms 16544 KB
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
#define int long long
int n , m , k;
int v[1005][1005] , h[1005][1005];



int get(vector<int> v){
	int n = v.size();
	int ansj = -1;
	stack<int> s;
	for(int i = 0 ; i <n;i++){
		while(s.size() && v[s.top()] >= v[i] ){
			int left;
			int u = s.top();
			s.pop();
			if(s.size()) left = s.top() + 1;
			else left = 0;
			int right = i - 1;
			ansj = max(ansj , (right - left + 1)*v[u]);
		}
		s.push(i);
	}
	while(s.size()){
		int u = s.top();
		s.pop();
		int left;
		if(s.size()) left = s.top() + 1;
		else left = 0;
		int right = n - 1;
		ansj = max(ansj , (right - left + 1)*v[u]);
	}
	return ansj;
}


int32_t main(){
	scanf("%lld%lld%lld" , &n , &m  ,&k);
	for(int i = 0 ; i<n;i++){
		for(int j = 0 ; j < m;j++)scanf("%lld" , &v[i][j]);
	}
	int l = 0 , r =(int) 1e9;
	int ansj = -1 , maxansjii;
	while(l<=r){
		int mid = (l+r)/2;
		for(int i = 0 ; i < n;i++){
			for(int j = 0 ; j <m ;j++){
				if(i){
					if(v[i][j] >= mid) h[i][j] = 1 + h[i-1][j];
					else h[i][j] = 0;
				}
				else{
					if(v[i][j] >= mid) h[i][j] = 1;
					else h[i][j] = 0;
				}
			}
		}
		int currarr = -1;
		for(int i = 0 ; i < n;i++){
			vector<int> t;
			for(int j = 0 ; j < m ; j++) t.pb(h[i][j]);
			currarr = max(currarr , get(t));
		}
		if(currarr >= k){
			ansj = max(ansj , mid);
			maxansjii = currarr;
			l = mid + 1;			
		}
		else r = mid - 1;
	}
	cout<<ansj<<" "<<maxansjii<<endl;
}

Compilation message

burrow.cpp: In function 'int32_t main()':
burrow.cpp:43:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld" , &n , &m  ,&k);
                                      ^
burrow.cpp:45:53: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int j = 0 ; j < m;j++)scanf("%lld" , &v[i][j]);
                                                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 532 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 3 ms 676 KB Output is correct
6 Correct 3 ms 816 KB Output is correct
7 Correct 3 ms 816 KB Output is correct
8 Correct 13 ms 1444 KB Output is correct
9 Correct 18 ms 2340 KB Output is correct
10 Correct 35 ms 2724 KB Output is correct
11 Correct 55 ms 3576 KB Output is correct
12 Correct 60 ms 5340 KB Output is correct
13 Correct 54 ms 5340 KB Output is correct
14 Correct 113 ms 6320 KB Output is correct
15 Correct 102 ms 6384 KB Output is correct
16 Correct 107 ms 6384 KB Output is correct
17 Correct 179 ms 8428 KB Output is correct
18 Correct 246 ms 9964 KB Output is correct
19 Correct 309 ms 11756 KB Output is correct
20 Correct 592 ms 13292 KB Output is correct
21 Correct 555 ms 14828 KB Output is correct
22 Correct 698 ms 16544 KB Output is correct
23 Correct 694 ms 16544 KB Output is correct
24 Correct 490 ms 16544 KB Output is correct
25 Correct 558 ms 16544 KB Output is correct