답안 #383956

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
383956 2021-03-31T05:31:34 Z mihai145 Gap (APIO16_gap) C++14
100 / 100
78 ms 2712 KB
#include "gap.h"
#include <vector>
#include <deque>
#include <algorithm>

const long long INF = 1e18;

long long findGap(int T, int N)
{
    if(T == 2) {
        long long a0, aN;
        MinMax(0LL, INF, &a0, &aN);
        long long L = (aN - a0) / (N - 1);

        if(N == 2) {
            return L;
        }
        if((aN - a0) % (N - 1) != 0) {
            ++L;
        }

        std::vector <long long> values;
        values.push_back(a0);

        long long prevRightEnd = a0;
        for(int i = 1; i <= N - 1; i++) {
            long long mn, mx;
            if(prevRightEnd + L - 1 < aN) {
                MinMax(prevRightEnd + 1, prevRightEnd + L, &mn, &mx);
            } else {
                if(prevRightEnd + 1 <= aN - 1) {
                    MinMax(prevRightEnd + 1, aN - 1, &mn, &mx);
                }
            }
            prevRightEnd = prevRightEnd + L;

            if(mn != -1) {
                values.push_back(mn);
                if(mx != mn) {
                    values.push_back(mx);
                }
            }
        }
        values.push_back(aN);

        long long dif = 0;
        for(int i = 1; i < (int)values.size(); i++) {
            dif = std::max(dif, values[i] - values[i - 1]);
        }

        return dif;
    }

    std::vector <long long> firstValues, lastValues;
    long long boundL = 0, boundR = INF;
    for(int i = 1; i <= N / 2; i++) {
        long long mn, mx;
        MinMax(boundL, boundR, &mn, &mx);
        firstValues.push_back(mn);
        lastValues.push_back(mx);
        boundL = mn + 1;
        boundR = mx - 1;
    }

    if(N % 2 == 1) {
        long long mn, mx;
        MinMax(boundL, boundR, &mn, &mx);
        firstValues.push_back(mn);
    }

    std::reverse(lastValues.begin(), lastValues.end());

    for(long long val : lastValues) {
        firstValues.push_back(val);
    }

    long long dif = 0;
    for(int i = 1; i < (int)firstValues.size(); i++) {
        dif = std::max(dif, firstValues[i] - firstValues[i - 1]);
    }

    return dif;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 12 ms 992 KB Output is correct
17 Correct 11 ms 1004 KB Output is correct
18 Correct 12 ms 1024 KB Output is correct
19 Correct 13 ms 1004 KB Output is correct
20 Correct 13 ms 1004 KB Output is correct
21 Correct 57 ms 2704 KB Output is correct
22 Correct 45 ms 2708 KB Output is correct
23 Correct 46 ms 2704 KB Output is correct
24 Correct 46 ms 2704 KB Output is correct
25 Correct 43 ms 2704 KB Output is correct
26 Correct 45 ms 2704 KB Output is correct
27 Correct 51 ms 2704 KB Output is correct
28 Correct 49 ms 2712 KB Output is correct
29 Correct 45 ms 2704 KB Output is correct
30 Correct 37 ms 2704 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 15 ms 876 KB Output is correct
17 Correct 18 ms 876 KB Output is correct
18 Correct 16 ms 1004 KB Output is correct
19 Correct 18 ms 876 KB Output is correct
20 Correct 9 ms 492 KB Output is correct
21 Correct 63 ms 2276 KB Output is correct
22 Correct 78 ms 2276 KB Output is correct
23 Correct 73 ms 2276 KB Output is correct
24 Correct 70 ms 2296 KB Output is correct
25 Correct 57 ms 2276 KB Output is correct
26 Correct 68 ms 2276 KB Output is correct
27 Correct 61 ms 2276 KB Output is correct
28 Correct 62 ms 2324 KB Output is correct
29 Correct 64 ms 2276 KB Output is correct
30 Correct 37 ms 1516 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct