답안 #946710

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946710 2024-03-14T23:23:14 Z Ice_man Gap (APIO16_gap) C++14
100 / 100
44 ms 4964 KB
#include <iostream>
#include <chrono>
#include <vector>
#include <algorithm>

#include "gap.h"

#define maxn 200005
#define maxlog 20
#define INF 1000000010
#define LINF 1000000000000000005
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define control cout<<"passed"<<endl;

#pragma GCC optimize("O3" , "Ofast" , "unroll-loops" , "fast-math")
#pragma GCC target("avx2")

using namespace std;

std::chrono::high_resolution_clock::time_point startT, currT;
constexpr double TIME_MULT = 1;

double timePassed()
{
    using namespace std::chrono;
    currT = high_resolution_clock::now();
    double time = duration_cast<duration<double>>(currT - startT).count();
    return time * TIME_MULT;
}

vector <long long> nums;


/**void MinMax(long long l , long long r , long long &mn , long long &mx)
{
    cout << l << " " << r << endl;
    int a , b;

    cin >> a >> b;
    mn = a;
    mx = b;
}*/



long long task1(int n)
{
    long long l = 1;
    long long r = LINF;

    int q = ((n + 1) / 2);

    while(q--)
    {
        long long mn, mx;
        MinMax(l, r, &mn, &mx);

        nums.pb(mn);
        nums.pb(mx);

        l = mn + 1;
        r = mx - 1;
    }

    sort(nums.begin(), nums.end());
    reverse(nums.begin(), nums.end());

    /**for(int e : nums)
        cout << e << " ";
    cout << endl;*/

    long long ans = 0;

    for(int i = 1; i < (int)(nums.size()); i++)
        ans = max(ans, abs(nums[i] - nums[i - 1]));

    return ans;
}






long long findGap(int t, int n)
{

    if(t == 1)
        return task1(n);

    long long l = 1;
    long long r = LINF;

    long long maxx = -1;
    long long minn = LINF;

    MinMax(1LL, LINF, &minn, &maxx);
    long long step = (maxx - minn + n) / n;

    l = minn;
    r = maxx;

    nums.pb(minn);

    for(long long i = l; i < r; i += step)
    {
        long long to = min(r - 1, i + step);
        MinMax(i + 1, to, &minn, &maxx);

        if(minn == -1 && maxx == -1)
            continue;

        nums.pb(minn);
        nums.pb(maxx);
    }

    nums.pb(r);

    //sort(nums.begin() , nums.end());
    //reverse(nums.begin() , nums.end());

    long long ans = -1;

    for(int i = 1; i < (int)(nums.size()); i++)
        ans = max(ans, abs(nums[i] - nums[i - 1]));

    return ans;
}


/**int main()
{
    int t , n;
    cin >> t >> n;

    cout << findGap(t , n) << endl;;

    return 0;
}*/



# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 2488 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 0 ms 2480 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 2 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 2 ms 2392 KB Output is correct
14 Correct 2 ms 2392 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 9 ms 2840 KB Output is correct
17 Correct 8 ms 2840 KB Output is correct
18 Correct 8 ms 2844 KB Output is correct
19 Correct 8 ms 2840 KB Output is correct
20 Correct 8 ms 2824 KB Output is correct
21 Correct 34 ms 3912 KB Output is correct
22 Correct 33 ms 3992 KB Output is correct
23 Correct 33 ms 3992 KB Output is correct
24 Correct 34 ms 4000 KB Output is correct
25 Correct 32 ms 3988 KB Output is correct
26 Correct 32 ms 3984 KB Output is correct
27 Correct 33 ms 3992 KB Output is correct
28 Correct 32 ms 3992 KB Output is correct
29 Correct 33 ms 3972 KB Output is correct
30 Correct 28 ms 3980 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 0 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 10 ms 2948 KB Output is correct
17 Correct 10 ms 2964 KB Output is correct
18 Correct 10 ms 2956 KB Output is correct
19 Correct 10 ms 2964 KB Output is correct
20 Correct 6 ms 2532 KB Output is correct
21 Correct 41 ms 3944 KB Output is correct
22 Correct 41 ms 3984 KB Output is correct
23 Correct 44 ms 3964 KB Output is correct
24 Correct 42 ms 3992 KB Output is correct
25 Correct 41 ms 4964 KB Output is correct
26 Correct 41 ms 3992 KB Output is correct
27 Correct 41 ms 3996 KB Output is correct
28 Correct 41 ms 3992 KB Output is correct
29 Correct 41 ms 3992 KB Output is correct
30 Correct 24 ms 3112 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct