Submission #655294

# Submission time Handle Problem Language Result Execution time Memory
655294 2022-11-03T18:36:02 Z ssense Gap (APIO16_gap) C++14
100 / 100
62 ms 1876 KB
#include <bits/stdc++.h>
#include "gap.h"
#define startt ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long  ll;
using namespace std;
#define vint vector<int>
#define all(v) v.begin(), v.end()
#define MOD 1000000007
#define MOD2 998244353
#define MX 1000000000
#define MXL 1000000000000000000
#define PI (ld)2*acos(0.0)
#define pb push_back
#define sc second
#define fr first
//#define int long long
#define endl '\n'
#define ld long double
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl

long long findGap(int T, int N)
{
    if(T == 1)
    {
        long long mn, mx;
        long long ask1 = 0, ask2 = 1e18;
        vector<long long> a(N);
        for(int i = 0; i < N; i++)
        {
            a[i] = -1;
        }
        long long nowi = 0, nowi2 = N-1;
        while(true)
        {
            if(nowi > nowi2)
            {
                break;
            }
            MinMax(ask1, ask2, &mn, &mx);
            if(mn == -1 && mx == -1)
            {
                break;
            }
            if(mn == mx)
            {
                a[nowi] = mn;
                break;
            }
            a[nowi] = mn;
            nowi++;
            a[nowi2] = mx;
            nowi2--;
            ask1 = mn+1;
            ask2 = mx-1;
        }
        long long ans = 0;
        for(int i = 0; i < N-1; i++)
        {
            assert(a[i] != -1);
            ans = max(ans, a[i+1]-a[i]);
        }
        return ans;
    }
    else
    {
        long long mn, mx;
        MinMax(0, 1e18, &mn, &mx);
        long long size = mx-mn-1;
        long long nowmin = mn+1, last = mn;
        long long ans = size/(N-1);
        for(int i = 0; i < N-1; i++)
        {
            long long nowmax = nowmin+size/(N-1);
            MinMax(nowmin, nowmax, &mn, &mx);
            if(mn != -1)
            {
                ans = max(ans, mn-last);
                last = mx;
            }
            nowmin = nowmax+1;
        }
        return ans;
    }
}
# 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 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 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 328 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 10 ms 680 KB Output is correct
17 Correct 13 ms 596 KB Output is correct
18 Correct 13 ms 720 KB Output is correct
19 Correct 12 ms 608 KB Output is correct
20 Correct 10 ms 592 KB Output is correct
21 Correct 38 ms 1824 KB Output is correct
22 Correct 44 ms 1824 KB Output is correct
23 Correct 42 ms 1824 KB Output is correct
24 Correct 40 ms 1876 KB Output is correct
25 Correct 32 ms 1832 KB Output is correct
26 Correct 37 ms 1864 KB Output is correct
27 Correct 37 ms 1800 KB Output is correct
28 Correct 37 ms 1852 KB Output is correct
29 Correct 39 ms 1864 KB Output is correct
30 Correct 34 ms 1796 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 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 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 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 14 ms 464 KB Output is correct
17 Correct 18 ms 464 KB Output is correct
18 Correct 13 ms 508 KB Output is correct
19 Correct 12 ms 420 KB Output is correct
20 Correct 6 ms 464 KB Output is correct
21 Correct 53 ms 1080 KB Output is correct
22 Correct 54 ms 1088 KB Output is correct
23 Correct 56 ms 1060 KB Output is correct
24 Correct 52 ms 1052 KB Output is correct
25 Correct 46 ms 1084 KB Output is correct
26 Correct 62 ms 1004 KB Output is correct
27 Correct 58 ms 1084 KB Output is correct
28 Correct 52 ms 1088 KB Output is correct
29 Correct 52 ms 1080 KB Output is correct
30 Correct 30 ms 1076 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct