Submission #712713

# Submission time Handle Problem Language Result Execution time Memory
712713 2023-03-19T14:15:20 Z onepunchac168 Gap (APIO16_gap) C++14
100 / 100
63 ms 1864 KB
#include <bits/stdc++.h>
#include "gap.h"

using namespace std;
long long a[100005];
#define ll long long
long long findGap(int t, int n)
{
    if (t==1){
        long long gmin=0;
        long long gmax=1e18;
        for (int i=1;i<=n/2;i++)
        {
            long long aa,bb;
            MinMax(gmin,gmax,&aa,&bb);
            a[i]=aa;
            a[n-i+1]=bb;
            gmin=aa+1;
            gmax=bb-1;
        }
        if (n%2==1)
        {
            long long aa,bb;
            MinMax(gmin,gmax,&aa,&bb);
            gmin=aa;
            gmax=bb;
            a[n/2+1]=gmin;
        }
        long long  res=0;
        for (int i=2;i<=n;i++)
        {
            res=max(res,a[i]-a[i-1]);
        }
        return res;
    }
    else
    {
        long long aa,bb;
        long long gmin=0;
        long long gmax=1e18;
        MinMax(gmin,gmax,&aa,&bb);
        gmin=aa;
        gmax=bb;
        ll pp=(bb-aa+1)/(n-1);
        ll res=0;
        ll before=-1;
        if (n==2)
        {
            return bb-aa;
        }
        for (int i=1;i<=n-1;i++)
        {
            if (i==n-1)
            {
                gmin=gmax+1;
                gmax=bb;
            }
            else if (i==1)
            {
                gmin=aa;
                gmax=aa+pp-1;
            }
            else
            {
                gmin=gmax+1;
                gmax=gmin+pp-1;
            }
            long long cc,dd;
            MinMax(gmin,gmax,&cc,&dd);
            if (cc==-1&&dd==-1)
            {
                continue;
            }
            else
            {
                if (cc!=dd)
                {
                    if (before!=-1)
                    {
                        res=max(res,cc-before);
                    }
                    before=dd;
                    continue;
                }
                else
                {
                    if (before!=-1)
                    {
                        res=max(res,cc-before);
                    }
                    before=dd;
                }
            }
        }
        return res;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 10 ms 592 KB Output is correct
17 Correct 9 ms 592 KB Output is correct
18 Correct 9 ms 688 KB Output is correct
19 Correct 9 ms 592 KB Output is correct
20 Correct 8 ms 656 KB Output is correct
21 Correct 36 ms 1820 KB Output is correct
22 Correct 39 ms 1864 KB Output is correct
23 Correct 38 ms 1820 KB Output is correct
24 Correct 39 ms 1828 KB Output is correct
25 Correct 35 ms 1828 KB Output is correct
26 Correct 36 ms 1860 KB Output is correct
27 Correct 36 ms 1820 KB Output is correct
28 Correct 36 ms 1744 KB Output is correct
29 Correct 50 ms 1828 KB Output is correct
30 Correct 29 ms 1820 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 13 ms 524 KB Output is correct
17 Correct 14 ms 464 KB Output is correct
18 Correct 14 ms 484 KB Output is correct
19 Correct 13 ms 512 KB Output is correct
20 Correct 7 ms 416 KB Output is correct
21 Correct 52 ms 1068 KB Output is correct
22 Correct 59 ms 1068 KB Output is correct
23 Correct 62 ms 1052 KB Output is correct
24 Correct 53 ms 1048 KB Output is correct
25 Correct 47 ms 1204 KB Output is correct
26 Correct 63 ms 1084 KB Output is correct
27 Correct 51 ms 1092 KB Output is correct
28 Correct 51 ms 1084 KB Output is correct
29 Correct 53 ms 1064 KB Output is correct
30 Correct 30 ms 1072 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct