Submission #340464

# Submission time Handle Problem Language Result Execution time Memory
340464 2020-12-27T16:16:07 Z beksultan04 Luxury burrow (IZhO13_burrow) C++14
100 / 100
956 ms 27988 KB
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-12
const int N = 1e5+12,INF=1e9+7;
int q[2001][2001],l[2001][2001],a[2001][2001],n,m;
int le[N],re[N];
int fun(){
    int ans=0,i,j;
    for (i=1;i<=n;++i){
        for (j=1;j<=m;++j){
            if (q[i][j] == 1){
                l[i][j] = l[i-1][j]+1;
            }
            else
                l[i][j]=0;
        }
    }
    for (i=1;i<=n;++i){
        vector <pii> v;
        v.pb({0,0});
        for (j=1;j<=m;++j){
            if (l[i][j] == 0){
                v.clear();
                v.pb({0,j});
            }
            else {
                while (!v.empty() && l[i][j] <= v.back().fr)
                    v.pop_back();
                le[j]=v.back().sc;
                v.pb({l[i][j],j});
            }
        }v.clear();
        v.pb({0,m+1});
        for (j=m;j>=1;j--){
            if (l[i][j] == 0){
                v.clear();
                v.pb({0,j});
            }
            else {
                while (!v.empty() && l[i][j] <= v.back().fr)
                    v.pop_back();
                re[j]=v.back().sc;
                v.pb({l[i][j],j});
            }
        }
        for(j=1;j<=m;j++)
            ans=max(ans,(re[j]-le[j]-1)*l[i][j]);
    }
    ret ans;
}

void full(int x){
    int i,j;
    for (i=1;i<=n;++i){
        for (j=1;j<=m;++j){
            if (a[i][j] >= x){
                q[i][j]=1;
            }
            else q[i][j]=0;
            l[i][j]=0;
        }
    }
}

main(){
    int i,j,k;
    scan3(n,m,k)
    vector<int>comp;
    for (i=1;i<=n;++i){
        for (j=1;j<=m;++j){
            scan1(a[i][j])
            comp.pb(a[i][j]);
        }
    }
    sort(all(comp));
    comp.erase(unique(all(comp)),comp.end());
    int l=0,r=int(comp.size())-1;
    while (r-l>1){
        int m = l+r>>1;
        full(comp[m]);
        int x = fun();
        if (x >= k){
            l=m;
        }
        else {
            r=m;
        }
    }
    full(comp[r]);
    int x = fun();
    if (x >= k)l=r;
    full(comp[l]);
    x = fun();
    cout <<comp[l]<<" "<<x;

}






Compilation message

burrow.cpp:81:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   81 | main(){
      |      ^
burrow.cpp: In function 'int main()':
burrow.cpp:95:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   95 |         int m = l+r>>1;
      |                 ~^~
burrow.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 | #define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~
burrow.cpp:83:5: note: in expansion of macro 'scan3'
   83 |     scan3(n,m,k)
      |     ^~~~~
burrow.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 | #define scan1(a) scanf("%d",&a);
      |                  ~~~~~^~~~~~~~~
burrow.cpp:87:13: note: in expansion of macro 'scan1'
   87 |             scan1(a[i][j])
      |             ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 752 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 6 ms 1772 KB Output is correct
9 Correct 13 ms 3180 KB Output is correct
10 Correct 30 ms 3688 KB Output is correct
11 Correct 55 ms 4456 KB Output is correct
12 Correct 26 ms 7272 KB Output is correct
13 Correct 38 ms 2408 KB Output is correct
14 Correct 90 ms 7776 KB Output is correct
15 Correct 88 ms 7776 KB Output is correct
16 Correct 141 ms 7776 KB Output is correct
17 Correct 80 ms 10336 KB Output is correct
18 Correct 346 ms 13404 KB Output is correct
19 Correct 288 ms 16604 KB Output is correct
20 Correct 650 ms 20180 KB Output is correct
21 Correct 765 ms 24020 KB Output is correct
22 Correct 920 ms 27988 KB Output is correct
23 Correct 956 ms 27860 KB Output is correct
24 Correct 464 ms 23636 KB Output is correct
25 Correct 411 ms 27860 KB Output is correct