Submission #340435

# Submission time Handle Problem Language Result Execution time Memory
340435 2020-12-27T15:34:36 Z beksultan04 Luxury burrow (IZhO13_burrow) C++14
0 / 100
75 ms 16896 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 fun(){
    memset(l,0,sizeof(l));
    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;
            }
        }
    }
    for (i=1;i<=n;++i){
        vector <pii> v;
        for (j=1;j<=m;++j){
            if (l[i][j] == 0){
                v.clear();
            }
            else {
                int pos = j;
                while (!v.empty() && l[i][j] <= v.back().fr){
                    pos = v.back().sc;
                    v.pop_back();
                }
                if (!v.empty()){
                    ans = max(ans,(j-v.back().sc+1)*v.back().fr);
                }
                v.pb({l[i][j],pos});
                ans = max(ans,(j-pos+1)*l[i][j]);

            }
        }
    }
    for (i=1;i<=n;++i){
        vector <pii> v;
        for (j=m;j>0;--j){
            if (l[i][j] == 0){
                v.clear();
            }
            else {
                int pos = j;
                while (!v.empty() && l[i][j] <= v.back().fr){
                    pos = v.back().sc;
                    v.pop_back();
                }
                if (!v.empty()){
                    ans = max(ans,(v.back().sc-j+1)*v.back().fr);
                }
                v.pb({l[i][j],pos});
                ans = max(ans,(pos-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;
        }
    }
}

main(){
    int i,j,k,ans1=0,ans2=0;
    scan3(n,m,k)

    for (i=1;i<=n;++i){
        for (j=1;j<=m;++j){
            scan1(a[i][j])
        }
    }
    int l=1,r=1e9;
    while (r-l>1){
        int m = l+r>>1;
        full(m);
        int x = fun();
        if (x >= k){
            l=m;
        }
        else {
            r=m;
        }
    }
    full(r);
    int x = fun();
    if (x >= k)l=r;
    full(l);
    x = fun();
    cout <<l<<" "<<x;

}






Compilation message

burrow.cpp:90:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   90 | main(){
      |      ^
burrow.cpp: In function 'int main()':
burrow.cpp:101:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  101 |         int m = l+r>>1;
      |                 ~^~
burrow.cpp:91:15: warning: unused variable 'ans1' [-Wunused-variable]
   91 |     int i,j,k,ans1=0,ans2=0;
      |               ^~~~
burrow.cpp:91:22: warning: unused variable 'ans2' [-Wunused-variable]
   91 |     int i,j,k,ans1=0,ans2=0;
      |                      ^~~~
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:92:5: note: in expansion of macro 'scan3'
   92 |     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:96:13: note: in expansion of macro 'scan1'
   96 |             scan1(a[i][j])
      |             ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 68 ms 16108 KB Output is correct
2 Correct 67 ms 16000 KB Output is correct
3 Correct 72 ms 16120 KB Output is correct
4 Correct 69 ms 16108 KB Output is correct
5 Correct 72 ms 16364 KB Output is correct
6 Correct 73 ms 16492 KB Output is correct
7 Correct 72 ms 15980 KB Output is correct
8 Incorrect 75 ms 16896 KB Output isn't correct
9 Halted 0 ms 0 KB -