답안 #683089

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683089 2023-01-17T16:27:27 Z Ronin13 호화 벙커 (IZhO13_burrow) C++14
100 / 100
876 ms 17844 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<ll,ll>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 1001;
int a[nmax][nmax];
int last[nmax][nmax];
int n, m;
int k;
int ans = 0;
bool check(int X){
    int mx = -1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(a[i][j] >= X)
                last[i][j] = last[i - 1][j] + 1;
            else last[i][j] = 0;
        }

        stack <int> st;
        vector <int> dr(m + 1), dl(m + 1);
        for(int j = 1; j <= m; j++){
            while(!st.empty()){
                int v = st.top();
                if(last[i][v] >= last[i][j])
                    st.pop();
                else break;
            }
            if(st.empty()) dl[j] = 0;
            else dl[j] = st.top();
            st.push(j);
        }
        while(!st.empty())
            st.pop();
        for(int j = m; j >= 1; j--){
            while(!st.empty()){
                int v = st.top();
                if(last[i][v] >= last[i][j])
                    st.pop();
                else break;
            }
            if(st.empty()) dr[j] = m + 1;
            else dr[j] = st.top();
            st.push(j);
        }
        for(int j = 1; j <= m; j++){
            //cout << dr[j] << ' ' << dl[j] << "\n";
            mx = max(mx, (dr[j] - dl[j] - 1) * last[i][j]);
        }
    }
    if(mx >= k) {
        ans = mx;
        return true;
    }
    return false;
}

int main(){
  //  freopen("school.in", "r", stdin);
 // freopen("school.out", "w", stdout);
    cin >> n >> m;
    cin >> k;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; ++j)
            cin >> a[i][j];
    }
    int l = 0, r = 1e9 + 1;
    while(l + 1 < r){
        int mid = (l + r) / 2;
        if(check(mid)) l = mid;
        else r = mid;
    }
    cout << l << ' ' << ans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 9 ms 1108 KB Output is correct
9 Correct 14 ms 1976 KB Output is correct
10 Correct 42 ms 2252 KB Output is correct
11 Correct 72 ms 2864 KB Output is correct
12 Correct 32 ms 4308 KB Output is correct
13 Correct 53 ms 1432 KB Output is correct
14 Correct 104 ms 4016 KB Output is correct
15 Correct 112 ms 4020 KB Output is correct
16 Correct 138 ms 4476 KB Output is correct
17 Correct 113 ms 4732 KB Output is correct
18 Correct 350 ms 7756 KB Output is correct
19 Correct 327 ms 7628 KB Output is correct
20 Correct 739 ms 12136 KB Output is correct
21 Correct 651 ms 13608 KB Output is correct
22 Correct 856 ms 17844 KB Output is correct
23 Correct 876 ms 17740 KB Output is correct
24 Correct 526 ms 10616 KB Output is correct
25 Correct 529 ms 10980 KB Output is correct