Submission #625171

# Submission time Handle Problem Language Result Execution time Memory
625171 2022-08-09T14:15:21 Z PoonYaPat Gap (APIO16_gap) C++14
100 / 100
56 ms 3252 KB
#include "gap.h"


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

vector<pll> v;
vector<ll> k;
ll mx,mn,ans;

ll findGap(int T, int n) {
    if (T==1) {
        ll l=0, r=1e18;
        while (k.size()<n) {
            MinMax(l,r,&mn,&mx);
            if (mn==mx) k.push_back(mn);
            else {
                k.push_back(mn);
                k.push_back(mx);
            }
            l=mn+1; r=mx-1;
        }
        sort(k.begin(),k.end());
        for (int i=1; i<k.size(); ++i) ans=max(ans,k[i]-k[i-1]);
    } else {
        MinMax(0,1e18,&mn,&mx);
        ll mmin=mn,mmax=mx;
        v.push_back(pll(mn,mn));

        ll wide=(mx-mn+n-2)/(n-1);

        for (int i=0; i<n-1; ++i) {
            if (mmin+1+wide*i > min(mmin+wide*(i+1),mmax-1)) break;
            MinMax(mmin+1+wide*i,min(mmin+wide*(i+1),mmax-1),&mn,&mx);
            if (mn!=-1) v.push_back(pll(mn,mx));
        }

        v.push_back(pll(mmax,mmax));

        for (int i=1; i<v.size(); ++i) ans=max(ans,v[i].first-v[i-1].second);
    }
    return ans;
}

Compilation message

gap.cpp: In function 'll findGap(int, int)':
gap.cpp:16:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   16 |         while (k.size()<n) {
      |                ~~~~~~~~^~
gap.cpp:26:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for (int i=1; i<k.size(); ++i) ans=max(ans,k[i]-k[i-1]);
      |                       ~^~~~~~~~~
gap.cpp:42:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for (int i=1; i<v.size(); ++i) ans=max(ans,v[i].first-v[i-1].second);
      |                       ~^~~~~~~~~
# 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 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 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 11 ms 848 KB Output is correct
17 Correct 11 ms 812 KB Output is correct
18 Correct 11 ms 848 KB Output is correct
19 Correct 12 ms 848 KB Output is correct
20 Correct 10 ms 848 KB Output is correct
21 Correct 41 ms 2196 KB Output is correct
22 Correct 38 ms 2204 KB Output is correct
23 Correct 37 ms 2192 KB Output is correct
24 Correct 45 ms 2240 KB Output is correct
25 Correct 34 ms 2200 KB Output is correct
26 Correct 37 ms 2172 KB Output is correct
27 Correct 39 ms 2128 KB Output is correct
28 Correct 38 ms 2312 KB Output is correct
29 Correct 39 ms 2204 KB Output is correct
30 Correct 37 ms 2156 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 0 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 336 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 812 KB Output is correct
17 Correct 13 ms 892 KB Output is correct
18 Correct 12 ms 848 KB Output is correct
19 Correct 12 ms 808 KB Output is correct
20 Correct 6 ms 464 KB Output is correct
21 Correct 56 ms 2204 KB Output is correct
22 Correct 51 ms 2176 KB Output is correct
23 Correct 52 ms 2200 KB Output is correct
24 Correct 52 ms 2204 KB Output is correct
25 Correct 45 ms 3252 KB Output is correct
26 Correct 51 ms 2204 KB Output is correct
27 Correct 50 ms 2240 KB Output is correct
28 Correct 54 ms 2204 KB Output is correct
29 Correct 56 ms 2240 KB Output is correct
30 Correct 24 ms 1436 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct