Submission #47846

# Submission time Handle Problem Language Result Execution time Memory
47846 2018-05-08T06:54:11 Z temurbek_khujaev Gap (APIO16_gap) C++17
30 / 100
120 ms 19552 KB
#include <bits/stdc++.h>
#include "gap.h"

using namespace std;

typedef long long ll;

ll v[223456];
#define fi first
#define se second

void upmax(ll &x,ll y) {
    x=max(x,y);
}

long long findGap(int T, int n)
{
    ll ans=0;

    if (T==1) {
        int l=0, r=n-1;
        MinMax(0ll,(1ll<<60),&v[0],&v[n-1]);

        for (int i=0;i<n/2;i++) {
            if (l+1==r) break;
            MinMax(v[l]+1,v[r]-1,&v[l+1],&v[r-1]);
            l++;
            r--;
        }

        for (int i=1;i<n;i++) {
            ans=max(ans,v[i]-v[i-1]);
        }
        return ans;
    } else {
        cout<<T<<endl;

        ll L,R;
        MinMax(0ll,(1ll<<60),&L,&R);
        set<pair<ll,pair<ll,ll> > > s;
        s.insert({L-R,{L,R}});
        ll lf=0,rg;

        do {


            ll d=-s.begin()->fi;
            if (d<ans) return ans;


            ll x=s.begin()->se.fi;
            ll y=s.begin()->se.se;
            s.erase(s.begin());
            ll f=d/3;
            ll m1,m2;
         //   cout<<d<< ' '<<x<< ' ' << y<<endl;
            MinMax(x+f,x+f+f,&m1,&m2);

            if (m1==-1) {

                ll mn1,mx1,mn2,mx2;

                MinMax(x+1,x+f-1,&mn1,&mx1);
                MinMax(x+2*f+1,y-1,&mn2,&mx2);


                if (mn1==-1&&mn2==-1)
                    return max(ans,d);

                else {

                    if (mx1!=-1&&mn2!=-1) upmax(ans,mn2-mx1);

                    if(mn1==-1) {
                        upmax(ans,mn2-x);
                    } else {
                        upmax(ans,mn1-x);
                        s.insert({mn1-mx1,{mn1,mx1}});
                        if (mn2!=-1) s.insert({mx1-mn2,{mn1,mn2}});
                    }

                    if(mn2==-1) {
                        upmax(ans,y-mx1);
                    } else {
                        upmax(ans,y-mx2);
                        s.insert({mn2-mx2,{mn2,mx2}});
                    }
                }

            } else {

                s.insert({x-m1,{x,m1}});
                s.insert({m2-y,{m2,y}});
                if (m1 != m2) s.insert({m1-m2,{m1,m2}});

            }

        } while (!s.empty());
    }
 //   cout<<ans<<endl;
    return ans;
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:42:12: warning: unused variable 'lf' [-Wunused-variable]
         ll lf=0,rg;
            ^~
gap.cpp:42:17: warning: unused variable 'rg' [-Wunused-variable]
         ll lf=0,rg;
                 ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 436 KB Output is correct
4 Correct 2 ms 440 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 584 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 608 KB Output is correct
9 Correct 2 ms 612 KB Output is correct
10 Correct 2 ms 648 KB Output is correct
11 Correct 3 ms 652 KB Output is correct
12 Correct 3 ms 736 KB Output is correct
13 Correct 3 ms 836 KB Output is correct
14 Correct 3 ms 836 KB Output is correct
15 Correct 2 ms 836 KB Output is correct
16 Correct 15 ms 1612 KB Output is correct
17 Correct 15 ms 2012 KB Output is correct
18 Correct 15 ms 2492 KB Output is correct
19 Correct 15 ms 2972 KB Output is correct
20 Correct 11 ms 3140 KB Output is correct
21 Correct 57 ms 6184 KB Output is correct
22 Correct 57 ms 8028 KB Output is correct
23 Correct 55 ms 9800 KB Output is correct
24 Correct 55 ms 11652 KB Output is correct
25 Correct 47 ms 12856 KB Output is correct
26 Correct 55 ms 13920 KB Output is correct
27 Correct 55 ms 13992 KB Output is correct
28 Correct 55 ms 13992 KB Output is correct
29 Correct 54 ms 14020 KB Output is correct
30 Correct 41 ms 14020 KB Output is correct
31 Correct 2 ms 14020 KB Output is correct
32 Correct 2 ms 14020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 14020 KB Expected int32, but "527609318252951603" found
2 Incorrect 2 ms 14020 KB Expected int32, but "158717465145313148" found
3 Incorrect 2 ms 14020 KB Expected int32, but "141470620841118761" found
4 Incorrect 2 ms 14020 KB Expected int32, but "281070690232818333" found
5 Incorrect 2 ms 14020 KB Expected EOF
6 Incorrect 2 ms 14020 KB Expected int32, but "54067555940387079" found
7 Incorrect 2 ms 14020 KB Expected int32, but "59713872839546348" found
8 Incorrect 2 ms 14020 KB Expected int32, but "63628383529967709" found
9 Incorrect 2 ms 14020 KB Expected int32, but "40066697874077492" found
10 Incorrect 2 ms 14020 KB Expected EOF
11 Incorrect 3 ms 14020 KB Expected int32, but "4966493272906105" found
12 Incorrect 2 ms 14020 KB Expected int32, but "4541692825618767" found
13 Incorrect 2 ms 14020 KB Expected int32, but "4642293045041442" found
14 Incorrect 2 ms 14020 KB Expected int32, but "6122034287537034" found
15 Incorrect 3 ms 14020 KB Expected EOF
16 Incorrect 13 ms 14020 KB Expected int32, but "410686271327381" found
17 Incorrect 13 ms 14020 KB Expected int32, but "430267194921600" found
18 Incorrect 11 ms 14020 KB Expected int32, but "487268024112545" found
19 Incorrect 11 ms 14020 KB Expected int32, but "599893247137814" found
20 Incorrect 8 ms 14020 KB Expected EOF
21 Incorrect 56 ms 14364 KB Expected int32, but "130710364094545" found
22 Incorrect 49 ms 14380 KB Expected int32, but "120119470217307" found
23 Incorrect 48 ms 14380 KB Expected int32, but "131100462117639" found
24 Incorrect 54 ms 14380 KB Expected int32, but "147711566772217" found
25 Incorrect 120 ms 19552 KB Expected EOF
26 Incorrect 43 ms 19552 KB Expected int32, but "162924923640912" found
27 Incorrect 49 ms 19552 KB Expected int32, but "117217672541541" found
28 Incorrect 49 ms 19552 KB Expected int32, but "109432203596644" found
29 Incorrect 48 ms 19552 KB Expected int32, but "123267759045505" found
30 Incorrect 14 ms 19552 KB Expected EOF
31 Incorrect 2 ms 19552 KB Expected int32, but "500000000000000000" found
32 Incorrect 2 ms 19552 KB Expected int32, but "500000000000000000" found