답안 #1003472

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003472 2024-06-20T11:30:29 Z amine_aroua Gap (APIO16_gap) C++17
100 / 100
42 ms 2824 KB
#include <bits/stdc++.h>
using namespace std;
#define intt long long
#define fore(i , n) for(int i = 0 ; i < n; i++)
#define forr(i , x ,y) for(int i = x;  i <= y;i++)
#define pb push_back
void MinMax(intt s , intt t , intt *mn , intt *mx);
long long findGap(int T, int N)
{
    if(T == 1)
    {
        intt mn = 0 , mx = 1e18*1LL;
        vector<intt> a;
        int n = N;
        while(n)
        {
            MinMax(mn , mx , &mn , &mx);
            a.pb(mn);
            n--;
            if(mn == mx)
                break;
            a.pb(mx);
            n--;
            mn++;
            mx--;
        }
        sort(a.begin() , a.end());
        intt ans = 0;
        fore(i , N - 1)
        {
            ans = max(ans , a[i + 1] - a[i]);
        }
        return ans;

    }
    intt mn , mx;
    MinMax(0ll , 1LL * 1e18 , &mn , &mx);
    intt gmn = mn , gmx = mx;
    intt d = (mx - mn + N - 2)/((N - 1));
    vector<intt> MinB(N , -1) , MaxB(N , -1);
    fore(i , N - 1)
    {
        intt lt = i * d + gmn , rt = (i + 1)*d + gmn - 1;
        MinMax(lt , rt , &mn , &mx);
        MinB[i] = mn;
        MaxB[i] = mx;
    }
    if((N - 1) * d + gmn <= gmx)
        MinB[N - 1]= MaxB[N - 1] = gmx;
    intt prv = MaxB[0];
    intt ans = (intt)d;
    forr(i , 1 , N - 1)
    {
        if(MinB[i] == -1)
            continue;
        ans = max(ans , MaxB[i] - MinB[i]);
        ans=  max(ans , MinB[i] - prv);
        prv = MaxB[i];
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 6 ms 980 KB Output is correct
17 Correct 8 ms 980 KB Output is correct
18 Correct 8 ms 980 KB Output is correct
19 Correct 6 ms 980 KB Output is correct
20 Correct 6 ms 980 KB Output is correct
21 Correct 24 ms 2256 KB Output is correct
22 Correct 26 ms 2256 KB Output is correct
23 Correct 25 ms 2256 KB Output is correct
24 Correct 31 ms 2248 KB Output is correct
25 Correct 28 ms 2256 KB Output is correct
26 Correct 32 ms 2304 KB Output is correct
27 Correct 28 ms 2248 KB Output is correct
28 Correct 24 ms 2256 KB Output is correct
29 Correct 25 ms 2256 KB Output is correct
30 Correct 21 ms 2256 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 9 ms 856 KB Output is correct
17 Correct 7 ms 856 KB Output is correct
18 Correct 7 ms 856 KB Output is correct
19 Correct 8 ms 856 KB Output is correct
20 Correct 5 ms 856 KB Output is correct
21 Correct 31 ms 2648 KB Output is correct
22 Correct 34 ms 2824 KB Output is correct
23 Correct 36 ms 2648 KB Output is correct
24 Correct 42 ms 2648 KB Output is correct
25 Correct 28 ms 2648 KB Output is correct
26 Correct 29 ms 2648 KB Output is correct
27 Correct 29 ms 2648 KB Output is correct
28 Correct 29 ms 2744 KB Output is correct
29 Correct 33 ms 2648 KB Output is correct
30 Correct 21 ms 2648 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct