답안 #114060

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
114060 2019-05-29T18:31:50 Z keko37 Gap (APIO16_gap) C++14
100 / 100
89 ms 3728 KB
#include<bits/stdc++.h>
#include "gap.h"

using namespace std;

typedef long long llint;

const llint INF = 1000000000000000007LL;

/*const int MAXN = 100005;

int nn, gmn, gmx, cnt;
llint a[MAXN];

void MinMax (llint s, llint t) {
    cnt++;
    cout << "bla " << s << " " << t << endl;
    llint x = INF, y = 0;
    for (int i = 0; i<nn; i++) {
        if (s <= a[i] && a[i] <= t) {
            cnt++;
            x = min(x, a[i]);
            y = max(y, a[i]);
        }
    }
    gmn = x;
    gmx = y;
}*/

long long findGap (int t, int n) {
    if (t == 1) {
        llint mn = -1, mx = INF + 1;
        vector <llint> v;
        while (v.size() < n) {
            //MinMax(mn + 1, mx - 1); mn = gmn; mx = gmx;
            MinMax(mn + 1, mx - 1, &mn, &mx);
            v.push_back(mn);
            if (mx != mn) v.push_back(mx);
            if (mx == mn) break;
        }
        sort(v.begin(), v.end());
        llint sol = 0;
        for (int i = 0; i < n-1; i++) {
            sol = max(sol, v[i+1] - v[i]);
        }
        return sol;
    } else {
        llint mn, mx, sol = 0;
        //MinMax(0, INF); mn = gmn; mx = gmx;
        MinMax(0, INF, &mn, &mx);
        llint d = mx - mn;
        llint len = d / (n-1);
        llint prosli = mn;
        llint a = mn + 1, b = min(a + len, mx - 1);
        while (a < mx) {
            llint currmn, currmx;
            //MinMax(a, b); currmn = gmn; currmx = gmx;
            MinMax(a, b, &currmn, &currmx);
            if (currmn != -1) {
                llint val = currmn - prosli;
                sol = max(sol, val);
                prosli = currmx;
            }
            a = b + 1;
            b = min(a + len, mx - 1);
        }
        sol = max(sol, mx - prosli);
        return sol;
    }
}

/*int main () {
    cin >> nn;
    for (int i = 0; i<nn; i++) {
        cin >> a[i];
    }
    cout << findGap(2, nn) << endl;
    cout << cnt;
    return 0;
}
*/

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:34:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (v.size() < n) {
                ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 356 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 14 ms 1280 KB Output is correct
17 Correct 14 ms 1280 KB Output is correct
18 Correct 15 ms 1408 KB Output is correct
19 Correct 14 ms 1280 KB Output is correct
20 Correct 11 ms 1024 KB Output is correct
21 Correct 51 ms 3676 KB Output is correct
22 Correct 52 ms 3696 KB Output is correct
23 Correct 52 ms 3696 KB Output is correct
24 Correct 54 ms 3696 KB Output is correct
25 Correct 44 ms 3440 KB Output is correct
26 Correct 54 ms 3728 KB Output is correct
27 Correct 54 ms 3696 KB Output is correct
28 Correct 57 ms 3696 KB Output is correct
29 Correct 51 ms 3696 KB Output is correct
30 Correct 40 ms 2928 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 19 ms 896 KB Output is correct
17 Correct 16 ms 896 KB Output is correct
18 Correct 16 ms 896 KB Output is correct
19 Correct 17 ms 896 KB Output is correct
20 Correct 9 ms 640 KB Output is correct
21 Correct 61 ms 2596 KB Output is correct
22 Correct 62 ms 2516 KB Output is correct
23 Correct 60 ms 2552 KB Output is correct
24 Correct 61 ms 2552 KB Output is correct
25 Correct 56 ms 2284 KB Output is correct
26 Correct 60 ms 2552 KB Output is correct
27 Correct 60 ms 2560 KB Output is correct
28 Correct 61 ms 2552 KB Output is correct
29 Correct 89 ms 2552 KB Output is correct
30 Correct 32 ms 1792 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct