Submission #441862

# Submission time Handle Problem Language Result Execution time Memory
441862 2021-07-06T11:44:14 Z leaked Bomb (IZhO17_bomb) C++14
58 / 100
1000 ms 87288 KB
#include <bits/stdc++.h>

#define vec vector
#define sz(x) (short int)x.size()
#define m_p make_pair
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;
typedef pair<ll,short int> pli;
typedef pair<short int,ll> pil;
typedef pair<short int,short int> pii;
auto rng=bind(uniform_int_distribution<short int>(1,32000),mt19937(time(0)));
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
const short int N=2503;
void mg(vec<pii> &a,vec<pii> &b,vec<array<short int,3>> &arr){
    int n=sz(a),m=sz(b);
    int i=0,j=0;
    short int mn=32000,mx=-32000,h=32000;
    arr.clear();
//    debug()<<imie(a)imie(b);
    for(short int k=0;k<n+m;k++){
        if((j==m) || (i!=n && a[i].f>b[j].f)) h=a[i].f,umin(mn,a[i++].s);
        else h=b[j].f,umax(mx,b[j++].s);
//        debug()<<imie(mn)imie(mx);
        if(mn!=32000 && mx!=-32000)arr.pb({mn,mx,h});
    }
//    debug()
    a.clear();b.clear();
}
short int up[N][N],dn[N][N],n,m;
short int lft1[N][N],rgt1[N][N],lft2[N][N],rgt2[N][N],a[N][N];
bool cmp(const array<short int,3> &f,const array<short int,3> &s){
    if(f[0]==s[0]){
        return f[1]>s[1];
    }
    return f[0]<s[0];
}
int tt;
int lst[N],mxm[N];
short int fck[N];
void do_this(vec<array<short int,3>> &x1,vec<array<short int,3>> &x2){
    tt++;
    reverse(all(x1));
    reverse(all(x2));
    /// now let us go by left
    short int r=32000,h1=-1;
    short int l=-32000,h2=-1;
    short int x=sz(x1),y=sz(x2);
    int blya=x+y;
    int _i=0,_j=0;
    vec<short int>lng;
    while(blya--){
        if(_i!=x && (_j==y || cmp(x1[_i],x2[_j]))){
            umax(l,x1[_i][0]);
            umin(r,x1[_i][1]);
            umax(h1,x1[_i][2]);
            _i++;
        }
        else{
            umax(l,x2[_j][0]);
            umin(r,x2[_j][1]);
            umax(h2,x2[_j][2]);
            _j++;
        }
        short int dl=r-l+1;
        if(!_i || !_j) continue;
        short int _h=h1+h2-1;
        if(lst[dl]!=tt){
            lst[dl]=tt;fck[dl]=-1;lng.pb(dl);
        }
        umax(fck[dl],_h);
    }
    reverse(all(lng));
    short int g=0;
    for(auto &z : lng){
        umin(mxm[g+1],(int)fck[z]);
        g=z;
    }
    return;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    cin>>n>>m;
    for(short int i=1;i<=n;i++){
        string s;
        cin>>s;
        for(short int j=0;j<m;j++){
            a[i][j+1]=s[j]-'0';
        }
    }
    for(int i=1;i<=m;i++){
        mxm[i]=1e9;
    }
    for(short int i=n;i>=1;i--){
        for(short int j=m;j>=1;j--){
            if(a[i][j]) dn[i][j]=dn[i+1][j]+1;
        }
    }
    for(short int i=1;i<=n;i++){
        for(short int j=m;j>=1;j--){
            if(a[i][j]) up[i][j]=up[i-1][j]+1;
        }
    }
    vec<pii>vc;
    for(short int i=1;i<=n;i++){
        vc.pb({-1,0});
        for(short int j=1;j<=m;j++){
            while(sz(vc) && vc.back().f>=up[i][j]) vc.pop_back();
            lft1[i][j]=vc.back().s;
            vc.pb({up[i][j],j});
        }
        vc.clear();
        vc.pb({-1,m+1});
        for(short int j=m;j>=1;j--){
            while(sz(vc) && vc.back().f>=up[i][j]) vc.pop_back();
            rgt1[i][j]=vc.back().s;
            vc.pb({up[i][j],j});
        }
    }
    for(short int i=1;i<=n;i++){
        vc.clear();
        vc.pb({-1,0});
        for(short int j=1;j<=m;j++){
            while(sz(vc) && vc.back().f>=dn[i][j]) vc.pop_back();
            lft2[i][j]=vc.back().s;
            vc.pb({dn[i][j],j});
        }
        vc.clear();
        vc.pb({-1,m+1});
        for(short int j=m;j>=1;j--){
            while(sz(vc) && vc.back().f>=dn[i][j]) vc.pop_back();
            rgt2[i][j]=vc.back().s;
            vc.pb({dn[i][j],j});
        }
    }
    vec<array<short int,3>>x1,x2;
    vec<pii>vc1,vc2;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(!a[i][j])continue;
//            debug()<<imie(i)imie(j);
            {
            short int u=j;
            while(u!=0){
                vc1.pb({up[i][u],lft1[i][u]+1});
                u=lft1[i][u];
            }
            u=j;
            while(u!=m+1){
                vc2.pb({up[i][u],rgt1[i][u]-1});
                u=rgt1[i][u];
            }
//            debug()<<imie(vc1)imie(vc2);
            mg(vc1,vc2,x1);
//            debug()<<imie(x1);
            u=j;
            while(u!=0){
                vc1.pb({dn[i][u],lft2[i][u]+1});
                u=lft2[i][u];
            }
            u=j;
            while(u!=m+1){
                vc2.pb({dn[i][u],rgt2[i][u]-1});
                u=rgt2[i][u];
            }
            mg(vc1,vc2,x2);
            }
            do_this(x1,x2);
//            debug()<<imie(x1)imie(x2);
        }
    }
    for(short int i=2;i<=m;i++) umin(mxm[i],mxm[i-1]);
    int ans=0;
    for(short int i=1;i<=m;i++){
        umax(ans,i*mxm[i]);
    }
    cout<<ans;
    return 0;
}

/*
10
2 1 2 2 1 1 3 2 5 5
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 844 KB Output is correct
3 Correct 29 ms 70420 KB Output is correct
4 Correct 28 ms 70412 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 844 KB Output is correct
9 Correct 1 ms 844 KB Output is correct
10 Correct 1 ms 712 KB Output is correct
11 Correct 1 ms 844 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 716 KB Output is correct
14 Correct 1 ms 716 KB Output is correct
15 Correct 1 ms 844 KB Output is correct
16 Correct 1 ms 844 KB Output is correct
17 Correct 2 ms 2252 KB Output is correct
18 Correct 2 ms 2124 KB Output is correct
19 Correct 2 ms 2764 KB Output is correct
20 Correct 2 ms 2764 KB Output is correct
21 Correct 1 ms 1612 KB Output is correct
22 Correct 2 ms 2252 KB Output is correct
23 Correct 3 ms 2892 KB Output is correct
24 Correct 2 ms 2508 KB Output is correct
25 Correct 3 ms 3276 KB Output is correct
26 Correct 6 ms 3276 KB Output is correct
27 Correct 75 ms 9768 KB Output is correct
28 Correct 10 ms 7628 KB Output is correct
29 Correct 485 ms 13072 KB Output is correct
30 Correct 31 ms 13748 KB Output is correct
31 Correct 21 ms 10392 KB Output is correct
32 Correct 21 ms 12752 KB Output is correct
33 Correct 41 ms 15008 KB Output is correct
34 Correct 10 ms 8912 KB Output is correct
35 Correct 20 ms 11996 KB Output is correct
36 Correct 104 ms 15972 KB Output is correct
37 Correct 1 ms 844 KB Output is correct
38 Execution timed out 1084 ms 87048 KB Time limit exceeded
39 Correct 1 ms 844 KB Output is correct
40 Correct 261 ms 31148 KB Output is correct
41 Correct 1 ms 844 KB Output is correct
42 Correct 8 ms 3276 KB Output is correct
43 Execution timed out 1079 ms 87236 KB Time limit exceeded
44 Correct 309 ms 15700 KB Output is correct
45 Execution timed out 1087 ms 87084 KB Time limit exceeded
46 Execution timed out 1075 ms 87108 KB Time limit exceeded
47 Execution timed out 1075 ms 87108 KB Time limit exceeded
48 Execution timed out 1082 ms 87108 KB Time limit exceeded
49 Execution timed out 1076 ms 87108 KB Time limit exceeded
50 Execution timed out 1071 ms 87236 KB Time limit exceeded
51 Execution timed out 1057 ms 87108 KB Time limit exceeded
52 Execution timed out 1078 ms 87116 KB Time limit exceeded
53 Execution timed out 1073 ms 87076 KB Time limit exceeded
54 Execution timed out 1079 ms 85308 KB Time limit exceeded
55 Execution timed out 1083 ms 84164 KB Time limit exceeded
56 Execution timed out 1083 ms 87108 KB Time limit exceeded
57 Execution timed out 1082 ms 80964 KB Time limit exceeded
58 Execution timed out 1073 ms 85744 KB Time limit exceeded
59 Execution timed out 1080 ms 82872 KB Time limit exceeded
60 Execution timed out 1048 ms 86852 KB Time limit exceeded
61 Execution timed out 1085 ms 87108 KB Time limit exceeded
62 Execution timed out 1088 ms 87040 KB Time limit exceeded
63 Execution timed out 1042 ms 87076 KB Time limit exceeded
64 Correct 733 ms 87152 KB Output is correct
65 Execution timed out 1077 ms 87196 KB Time limit exceeded
66 Execution timed out 1082 ms 87120 KB Time limit exceeded
67 Execution timed out 1087 ms 87108 KB Time limit exceeded
68 Execution timed out 1079 ms 87108 KB Time limit exceeded
69 Execution timed out 1080 ms 80676 KB Time limit exceeded
70 Correct 404 ms 58624 KB Output is correct
71 Correct 725 ms 79488 KB Output is correct
72 Correct 927 ms 80852 KB Output is correct
73 Correct 960 ms 80104 KB Output is correct
74 Correct 931 ms 82480 KB Output is correct
75 Correct 998 ms 83516 KB Output is correct
76 Correct 1000 ms 84264 KB Output is correct
77 Execution timed out 1063 ms 84108 KB Time limit exceeded
78 Execution timed out 1004 ms 84724 KB Time limit exceeded
79 Correct 385 ms 67908 KB Output is correct
80 Correct 385 ms 69088 KB Output is correct
81 Correct 444 ms 68792 KB Output is correct
82 Execution timed out 1071 ms 86212 KB Time limit exceeded
83 Execution timed out 1048 ms 86492 KB Time limit exceeded
84 Correct 383 ms 63148 KB Output is correct
85 Correct 886 ms 87144 KB Output is correct
86 Execution timed out 1094 ms 86932 KB Time limit exceeded
87 Correct 842 ms 87256 KB Output is correct
88 Execution timed out 1041 ms 85248 KB Time limit exceeded
89 Execution timed out 1095 ms 87056 KB Time limit exceeded
90 Correct 552 ms 70016 KB Output is correct
91 Correct 993 ms 87144 KB Output is correct
92 Execution timed out 1091 ms 86584 KB Time limit exceeded
93 Execution timed out 1088 ms 86856 KB Time limit exceeded
94 Execution timed out 1083 ms 86568 KB Time limit exceeded
95 Execution timed out 1058 ms 86428 KB Time limit exceeded
96 Execution timed out 1062 ms 86176 KB Time limit exceeded
97 Execution timed out 1074 ms 87288 KB Time limit exceeded
98 Execution timed out 1072 ms 85956 KB Time limit exceeded
99 Execution timed out 1078 ms 86764 KB Time limit exceeded
100 Execution timed out 1080 ms 86776 KB Time limit exceeded