Submission #83784

# Submission time Handle Problem Language Result Execution time Memory
83784 2018-11-10T14:36:01 Z popovicirobert Gap (APIO16_gap) C++14
100 / 100
83 ms 2268 KB
#include "gap.h"
#define ll long long
#include <bits/stdc++.h>

using namespace std;

const int MAXN = (int) 1e5;
const ll INF = 1e18;

ll arr[MAXN + 1];

long long findGap(int T, int N) {
    ll A, B;
    if(T == 1) {
        ll ans = 0;
        A = 0;
        B = INF;
        for(int i = 1; i <= N - i + 1; i++) {
            ll mn, mx;
            MinMax(A, B, &arr[i], &arr[N - i + 1]);
            A = arr[i] + 1;
            B = arr[N - i + 1] - 1;
        }
        for(int i = 1; i < N; i++) {
            ans = max(ans, arr[i + 1] - arr[i]);
        }
        return ans;
    }
    MinMax(0, INF, &A, &B);
    ll dif = (B - A + N - 2) / (N - 1);
    ll cur = A, ans = dif;
    while(cur < B) {
        ll s, t, mn, mx;
        s = t = cur + 1;
        do {
            t += dif;
            if(t > B) {
                t = min(t, B);
            }
            MinMax(s, t, &mn, &mx);
            if(mx == -1) {
                continue;
            }
            else {
                break;
            }
        }while(1);
        ans = max(ans, mn - cur);
        dif = max(dif, ans);
        cur = mx;
        //cerr << cur << " ";
    }
	return ans;
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:19:16: warning: unused variable 'mn' [-Wunused-variable]
             ll mn, mx;
                ^~
gap.cpp:19:20: warning: unused variable 'mx' [-Wunused-variable]
             ll mn, mx;
                    ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 2 ms 616 KB Output is correct
6 Correct 3 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 2 ms 644 KB Output is correct
9 Correct 3 ms 644 KB Output is correct
10 Correct 2 ms 644 KB Output is correct
11 Correct 3 ms 644 KB Output is correct
12 Correct 3 ms 644 KB Output is correct
13 Correct 3 ms 644 KB Output is correct
14 Correct 3 ms 644 KB Output is correct
15 Correct 3 ms 644 KB Output is correct
16 Correct 16 ms 976 KB Output is correct
17 Correct 17 ms 992 KB Output is correct
18 Correct 16 ms 1000 KB Output is correct
19 Correct 16 ms 1000 KB Output is correct
20 Correct 12 ms 1004 KB Output is correct
21 Correct 56 ms 2268 KB Output is correct
22 Correct 57 ms 2268 KB Output is correct
23 Correct 58 ms 2268 KB Output is correct
24 Correct 63 ms 2268 KB Output is correct
25 Correct 58 ms 2268 KB Output is correct
26 Correct 58 ms 2268 KB Output is correct
27 Correct 56 ms 2268 KB Output is correct
28 Correct 62 ms 2268 KB Output is correct
29 Correct 83 ms 2268 KB Output is correct
30 Correct 49 ms 2268 KB Output is correct
31 Correct 2 ms 2268 KB Output is correct
32 Correct 2 ms 2268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2268 KB Output is correct
2 Correct 2 ms 2268 KB Output is correct
3 Correct 2 ms 2268 KB Output is correct
4 Correct 2 ms 2268 KB Output is correct
5 Correct 2 ms 2268 KB Output is correct
6 Correct 2 ms 2268 KB Output is correct
7 Correct 2 ms 2268 KB Output is correct
8 Correct 2 ms 2268 KB Output is correct
9 Correct 2 ms 2268 KB Output is correct
10 Correct 2 ms 2268 KB Output is correct
11 Correct 3 ms 2268 KB Output is correct
12 Correct 3 ms 2268 KB Output is correct
13 Correct 3 ms 2268 KB Output is correct
14 Correct 3 ms 2268 KB Output is correct
15 Correct 3 ms 2268 KB Output is correct
16 Correct 11 ms 2268 KB Output is correct
17 Correct 12 ms 2268 KB Output is correct
18 Correct 12 ms 2268 KB Output is correct
19 Correct 12 ms 2268 KB Output is correct
20 Correct 9 ms 2268 KB Output is correct
21 Correct 37 ms 2268 KB Output is correct
22 Correct 37 ms 2268 KB Output is correct
23 Correct 37 ms 2268 KB Output is correct
24 Correct 43 ms 2268 KB Output is correct
25 Correct 76 ms 2268 KB Output is correct
26 Correct 60 ms 2268 KB Output is correct
27 Correct 46 ms 2268 KB Output is correct
28 Correct 41 ms 2268 KB Output is correct
29 Correct 42 ms 2268 KB Output is correct
30 Correct 27 ms 2268 KB Output is correct
31 Correct 2 ms 2268 KB Output is correct
32 Correct 3 ms 2268 KB Output is correct