답안 #953236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
953236 2024-03-25T17:49:43 Z n3rm1n Gap (APIO16_gap) C++17
89.1235 / 100
43 ms 3456 KB
#include<bits/stdc++.h>
#include "gap.h"

using namespace std;
const long long MAXN = 2e5 + 10;
long long a[MAXN];
long long findGap(int T, int N)
{
    if(T == 1)
    {
        long long s = 0, t = (long long)(1e18);
        long long mn, mx;
        long long n = N;
        long long filled0 = 0, filled1 = n+1;

        while(filled0 + 1 <= filled1 - 1)
        {

            MinMax(s, t, &mn, &mx);

            if(mn == mx)
            {
                filled0 ++;
                a[filled0] = mn;
                n --;
                break;
            }
            filled0 ++;
            filled1 --;
            n-= 2;
            a[filled0] = mn;
            a[filled1] = mx;

            s = mn + 1;
            t = mx - 1;
        }
        long long ans = -1;
        for (long long i = 2; i <= N; ++ i)
            ans = max(ans, (long long) (a[i] - a[i-1]));
        return ans;
    }


    long long n = N;
    long long s = 0, t = (long long)(1e18);
    long long mn, mx;
    long long range_l = 0, range_r;
    long long l;
    MinMax(s, t, &mn, &mx);
    range_l = mn;
    range_r = mx;
    l = range_r - range_l + 1;
    long long x = (l + n - 1)/n;
    //if(x * (n-1) < l)x ++;
    long long last = range_l, cache = 0;
    long long st = last;
    long long ans = 0;
    while(last < range_r)
    {

        s = last + 1;
        t = last + x + 1;
        MinMax(s, t, &mn, &mx);

        if(mx != -1 && mn > last && (mn >= s && mn <= t) && (mx >= s && mx <= t))
        {
            ans = max(ans, mn - st);
            st = mx;
        }

        last += x;
    }
    return ans;
}
/**
2 5
2 3 7 17 19
*/

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:55:31: warning: unused variable 'cache' [-Wunused-variable]
   55 |     long long last = range_l, cache = 0;
      |                               ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 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 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 8 ms 2544 KB Output is correct
17 Correct 8 ms 2704 KB Output is correct
18 Correct 8 ms 2536 KB Output is correct
19 Correct 8 ms 2700 KB Output is correct
20 Correct 6 ms 2536 KB Output is correct
21 Correct 30 ms 3448 KB Output is correct
22 Correct 30 ms 3356 KB Output is correct
23 Correct 30 ms 3444 KB Output is correct
24 Correct 30 ms 3440 KB Output is correct
25 Correct 27 ms 3444 KB Output is correct
26 Correct 30 ms 3456 KB Output is correct
27 Correct 30 ms 3436 KB Output is correct
28 Correct 30 ms 3432 KB Output is correct
29 Correct 30 ms 3452 KB Output is correct
30 Correct 25 ms 3428 KB Output is correct
31 Correct 1 ms 2404 KB Output is correct
32 Correct 0 ms 2404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2404 KB Output is correct
2 Correct 1 ms 2404 KB Output is correct
3 Correct 1 ms 2404 KB Output is correct
4 Correct 0 ms 2516 KB Output is correct
5 Correct 1 ms 2400 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 2404 KB Output is correct
9 Correct 1 ms 2404 KB Output is correct
10 Correct 1 ms 2404 KB Output is correct
11 Correct 1 ms 2404 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 2496 KB Output is correct
15 Correct 1 ms 2404 KB Output is correct
16 Correct 11 ms 2956 KB Output is correct
17 Correct 10 ms 2544 KB Output is correct
18 Correct 10 ms 2552 KB Output is correct
19 Correct 10 ms 2552 KB Output is correct
20 Partially correct 5 ms 2532 KB Partially correct
21 Correct 41 ms 2936 KB Output is correct
22 Correct 43 ms 2684 KB Output is correct
23 Correct 43 ms 2692 KB Output is correct
24 Correct 41 ms 2692 KB Output is correct
25 Correct 39 ms 2676 KB Output is correct
26 Correct 41 ms 2700 KB Output is correct
27 Correct 41 ms 2684 KB Output is correct
28 Correct 41 ms 2696 KB Output is correct
29 Correct 40 ms 2696 KB Output is correct
30 Partially correct 23 ms 2684 KB Partially correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct