Submission #569179

# Submission time Handle Problem Language Result Execution time Memory
569179 2022-05-26T22:49:48 Z Deepesson Gap (APIO16_gap) C++17
100 / 100
75 ms 8508 KB
#include <bits/stdc++.h>

#include "gap.h"

void MinMax(long long, long long, long long*, long long*);

using ll = long long;
const ll left = 0,right = 1e18;
long long findGap(int T, int N)
{
    if(T==1)
     {
        std::map<ll,bool> mapa;
        ll l=-1,r=1e18;++r;
        while(mapa.size()!=N){
            ll a,b;
            if(l+1>r-1)break;
            MinMax(l+1,r-1,&a,&b);
            if(a!=-1){
                mapa[a]=true;
                l=a;
            }
            if(b!=-1){
                mapa[b]=true;
                r=b;
            }
            if(a==b&&a==-1)break;
        }
        ll max=0;
        std::vector<ll> vec;
        std::sort(vec.begin(),vec.end());
        for(auto&x:mapa)vec.push_back(x.first);
        for(int i=1;i!=vec.size();++i)max=std::max(max,vec[i]-vec[i-1]);
        return max;
    }
    else {
        ll a,b;
        MinMax(left,right,&a,&b);
        if(N==2)return b-a;

        ll falta = ((b-1)-(a+1)+1);
        ll ops = 3*N;
        ops-=N+1;
        ops-=N-2;
        ll cada = falta/ops;
        ll bonus = falta%ops;
        ll start = a+1;
        ll prev=a;
        ll ans=0;
        for(int i=0;i!=ops;++i){
            ll anda = cada;
            if(bonus){
                ++anda;
                --bonus;
            }
            ll end = start+anda-1;
            ll x,y;
            MinMax(start,end,&x,&y);
            if(x!=-1){
                ans=std::max(ans,x-prev);
                prev=y;
            }
            start=end+1;
        }
        ans=std::max(ans,b-prev);
        return ans;
    }
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:15:26: warning: comparison of integer expressions of different signedness: 'std::map<long long int, bool>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   15 |         while(mapa.size()!=N){
      |               ~~~~~~~~~~~^~~
gap.cpp:33:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for(int i=1;i!=vec.size();++i)max=std::max(max,vec[i]-vec[i-1]);
      |                     ~^~~~~~~~~~~~
# 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 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 396 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 17 ms 2384 KB Output is correct
17 Correct 13 ms 2384 KB Output is correct
18 Correct 14 ms 2424 KB Output is correct
19 Correct 15 ms 2384 KB Output is correct
20 Correct 13 ms 2372 KB Output is correct
21 Correct 75 ms 8492 KB Output is correct
22 Correct 64 ms 8476 KB Output is correct
23 Correct 59 ms 8484 KB Output is correct
24 Correct 65 ms 8460 KB Output is correct
25 Correct 63 ms 8408 KB Output is correct
26 Correct 62 ms 8508 KB Output is correct
27 Correct 61 ms 8480 KB Output is correct
28 Correct 68 ms 8480 KB Output is correct
29 Correct 72 ms 8488 KB Output is correct
30 Correct 52 ms 8472 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 0 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 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 17 ms 508 KB Output is correct
17 Correct 16 ms 464 KB Output is correct
18 Correct 16 ms 488 KB Output is correct
19 Correct 12 ms 464 KB Output is correct
20 Correct 6 ms 464 KB Output is correct
21 Correct 56 ms 1068 KB Output is correct
22 Correct 50 ms 1048 KB Output is correct
23 Correct 56 ms 1104 KB Output is correct
24 Correct 56 ms 1060 KB Output is correct
25 Correct 45 ms 1096 KB Output is correct
26 Correct 50 ms 1084 KB Output is correct
27 Correct 48 ms 1060 KB Output is correct
28 Correct 55 ms 1084 KB Output is correct
29 Correct 49 ms 1076 KB Output is correct
30 Correct 30 ms 1100 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct