Submission #309467

# Submission time Handle Problem Language Result Execution time Memory
309467 2020-10-03T14:12:06 Z cig32 Gap (APIO16_gap) C++14
100 / 100
76 ms 2416 KB
#include "gap.h"
 
#include<bits/stdc++.h>
using namespace std;
long long findGap(int T, int N) {
    if(T==1){
        long long leftbound=0, rightbound=1e18;
        priority_queue <long long> pq;
        long long cnt=0;
        for(int i=0;i<=N/2;i++){
            long long l,r;
            if(cnt!=N){
                MinMax(leftbound,rightbound,&l,&r);
                pq.push(l);
                cnt++;
                if(l!=r){
                    pq.push(r);
                    cnt++;
                    leftbound=l+1;
                    rightbound=r-1;
                }
                else break;
            }
            else break;
        }
        long long prev=pq.top();
        pq.pop();
        long long ans=0;
        while(pq.size()!=0){
            ans=max(ans,prev-pq.top());
            prev=pq.top();
            pq.pop();
        }
        return ans;
    }
    else{
        // TODO: implementationt
        long long leftbound, rightbound;
        long long haha=1e18;
        MinMax(0, haha, &leftbound, &rightbound);
        if(N==2){
            return rightbound-leftbound;
        }
        leftbound++;
        rightbound--;
        long long range_size=ceil((rightbound-leftbound)*1.0/N);
        long long dbsic_noob=(rightbound-leftbound+1);
        long long dbsic_sofai=ceil(dbsic_noob*1.0/(range_size));
        long long arr[dbsic_sofai];
        long long running=leftbound-1;
        for(int i=0;i<dbsic_sofai;i++){
            arr[i]=range_size-1;
            if(i<(dbsic_noob/range_size)){
                arr[i]++;
            }
            //printf("%lld\n",arr[i]);
        }
        long long ans=0,ans1=0,ans2=0;
        long long prevl, prevr=-1;
        bool ok=true;
        for(int i=0;i<dbsic_sofai;i++){
            long long l,r;
            MinMax(running+1,running+arr[i],&l,&r);
            running+=arr[i];
            if(l==-1 && r==-1){
                continue;
            }
            else{
                if(ok==true){
                    ok=false;
                    ans1=l-leftbound+1;
                }
                ans2=rightbound+1-r;
                if(i!=0 && prevr!=-1 && ans<(l-prevr)){
                    ans=l-prevr;
                }
                prevl=l, prevr=r;
            }
        }
        ans1=max(ans1,ans2);
        ans=max(ans,ans1);
        return ans;
    }
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:59:19: warning: variable 'prevl' set but not used [-Wunused-but-set-variable]
   59 |         long long prevl, prevr=-1;
      |                   ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 16 ms 896 KB Output is correct
17 Correct 15 ms 896 KB Output is correct
18 Correct 15 ms 896 KB Output is correct
19 Correct 15 ms 992 KB Output is correct
20 Correct 11 ms 896 KB Output is correct
21 Correct 67 ms 2288 KB Output is correct
22 Correct 62 ms 2268 KB Output is correct
23 Correct 68 ms 2288 KB Output is correct
24 Correct 60 ms 2288 KB Output is correct
25 Correct 58 ms 2288 KB Output is correct
26 Correct 60 ms 2288 KB Output is correct
27 Correct 61 ms 2272 KB Output is correct
28 Correct 67 ms 2288 KB Output is correct
29 Correct 61 ms 2288 KB Output is correct
30 Correct 46 ms 2416 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 17 ms 768 KB Output is correct
17 Correct 16 ms 768 KB Output is correct
18 Correct 16 ms 768 KB Output is correct
19 Correct 16 ms 768 KB Output is correct
20 Correct 7 ms 768 KB Output is correct
21 Correct 68 ms 2040 KB Output is correct
22 Correct 69 ms 1896 KB Output is correct
23 Correct 71 ms 1912 KB Output is correct
24 Correct 66 ms 1912 KB Output is correct
25 Correct 60 ms 2040 KB Output is correct
26 Correct 71 ms 1868 KB Output is correct
27 Correct 66 ms 1956 KB Output is correct
28 Correct 68 ms 1912 KB Output is correct
29 Correct 76 ms 1912 KB Output is correct
30 Correct 33 ms 1992 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct