Submission #535578

# Submission time Handle Problem Language Result Execution time Memory
535578 2022-03-10T14:13:57 Z daisy Gap (APIO16_gap) C++17
100 / 100
71 ms 1104 KB
#include<iostream>
#include "gap.h"
#define l 1000000000000000000
using namespace std;
long long subt1(long long n)
{
    long long tf,ts,pf,ps,mr=0;

    MinMax(0,l,&tf,&ts);

    for(int i=2;i<=n/2;i++)
    {
        pf=tf;ps=ts;
        MinMax(pf+1,ps-1,&tf,&ts);

        if(tf-pf>mr) mr=tf-pf;
        if(ps-ts>mr) mr=ps-ts;
    }
    if(n%2)
    {
        if(tf+1<=ts-1)
        MinMax(tf+1,ts-1,&pf,&ps);
        if(pf-tf>mr) mr=pf-tf;
        if(ts-pf>mr) mr=ts-pf;
    }
    else if(ts-tf>mr) mr=ts-tf;
    return mr;
}
long long subt2(long long n)
{
    long long tl,tr,le,ri,mi,ma,pma,mr=0;
    MinMax(0,l,&tl,&tr);

    long long in=(tr-tl+1)/(n-1);
    le=tl+1;ri=tl+in;
    pma=tl;

    for(int i=1;i<n;i++)
    {
        MinMax(le,ri,&mi,&ma);
        le+=in;ri+=in;
        if(mi!=-1 && mr<mi-pma)
          mr=mi-pma;
        if(ma!=-1) pma=ma;
    }
    if(le<=tr)
    {
        MinMax(le,tr,&mi,&ma);
        if(mi==-1)
        {
            mr=max(mr,tr+1-pma);
        }
        else
        {
            mr=max(mr,mi-pma);
            mr=max(mr,tr+1-ma);
        }
    }
    return mr;
}
long long findGap(int T, int N)
{
    if(T==1)
    return subt1(N);
	else return subt2(N);
}
# 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 0 ms 208 KB Output is correct
7 Correct 1 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 1 ms 336 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 10 ms 432 KB Output is correct
17 Correct 9 ms 508 KB Output is correct
18 Correct 9 ms 520 KB Output is correct
19 Correct 9 ms 464 KB Output is correct
20 Correct 7 ms 464 KB Output is correct
21 Correct 38 ms 1060 KB Output is correct
22 Correct 46 ms 1064 KB Output is correct
23 Correct 40 ms 968 KB Output is correct
24 Correct 36 ms 968 KB Output is correct
25 Correct 31 ms 1104 KB Output is correct
26 Correct 36 ms 1076 KB Output is correct
27 Correct 39 ms 1084 KB Output is correct
28 Correct 42 ms 1088 KB Output is correct
29 Correct 38 ms 1080 KB Output is correct
30 Correct 27 ms 1104 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 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 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 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 14 ms 464 KB Output is correct
17 Correct 14 ms 512 KB Output is correct
18 Correct 13 ms 512 KB Output is correct
19 Correct 15 ms 488 KB Output is correct
20 Correct 5 ms 464 KB Output is correct
21 Correct 49 ms 956 KB Output is correct
22 Correct 49 ms 1040 KB Output is correct
23 Correct 54 ms 1084 KB Output is correct
24 Correct 53 ms 1080 KB Output is correct
25 Correct 50 ms 968 KB Output is correct
26 Correct 56 ms 1080 KB Output is correct
27 Correct 71 ms 1084 KB Output is correct
28 Correct 61 ms 1052 KB Output is correct
29 Correct 49 ms 976 KB Output is correct
30 Correct 26 ms 1072 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct