Submission #255790

# Submission time Handle Problem Language Result Execution time Memory
255790 2020-08-01T20:42:42 Z Osama_Alkhodairy Gap (APIO16_gap) C++17
100 / 100
69 ms 2844 KB
#include <bits/stdc++.h>
#include "gap.h"
//~ #include "grader.cpp"
using namespace std;
#define ll long long

ll findGap(int T, int N){
    ll mn, mx;
    if(T == 1){
        MinMax(0, 1e18, &mn, &mx);
        ll ans = 0;
        for(int i = 0 ; i < (N + 1) / 2 - 1 ; i++){
            ll new_mn, new_mx;
            MinMax(mn + 1, mx - 1, &new_mn, &new_mx);
            if(new_mn == -1){
                ans = max(ans, mx - mn);
            }
            else{
                ans = max(ans, new_mn - mn);
                ans = max(ans, mx - new_mx);
            }
            mn = new_mn;
            mx = new_mx;
        }
        if(mn != mx) ans = max(ans, mx - mn);
        return ans;
    }
    MinMax(0, 1e18, &mn, &mx);
    ll l = mn, r = mx;
    ll g = (r - l - (N - 2)) / (N - 1);
    ll cur_l = l;
    vector <ll> mnq, mxq;
    for(int i = 0 ; cur_l < r ; i++){
        ll sz = g + (i < (r - l - (N - 2)) % (N - 1));
        ll cur_r = cur_l + sz;
        MinMax(cur_l, cur_r, &mn, &mx);
        if(mn != -1){
            mnq.push_back(mn);
            mxq.push_back(mx);
        }
        cur_l += sz + 1;
    }
    ll ans = (r - l + N - 2) / (N - 1);
    for(int i = 1 ; i < (int)mnq.size() ; i++){
        ans = max(ans, mnq[i] - mxq[i - 1]);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 12 ms 512 KB Output is correct
17 Correct 12 ms 512 KB Output is correct
18 Correct 13 ms 512 KB Output is correct
19 Correct 12 ms 512 KB Output is correct
20 Correct 9 ms 512 KB Output is correct
21 Correct 50 ms 1144 KB Output is correct
22 Correct 51 ms 1144 KB Output is correct
23 Correct 57 ms 1144 KB Output is correct
24 Correct 54 ms 1144 KB Output is correct
25 Correct 42 ms 1144 KB Output is correct
26 Correct 50 ms 1168 KB Output is correct
27 Correct 49 ms 1144 KB Output is correct
28 Correct 52 ms 1184 KB Output is correct
29 Correct 49 ms 1056 KB Output is correct
30 Correct 35 ms 1144 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 19 ms 888 KB Output is correct
17 Correct 16 ms 896 KB Output is correct
18 Correct 16 ms 888 KB Output is correct
19 Correct 16 ms 888 KB Output is correct
20 Correct 8 ms 512 KB Output is correct
21 Correct 66 ms 2204 KB Output is correct
22 Correct 68 ms 2332 KB Output is correct
23 Correct 68 ms 2380 KB Output is correct
24 Correct 68 ms 2204 KB Output is correct
25 Correct 63 ms 2844 KB Output is correct
26 Correct 69 ms 2332 KB Output is correct
27 Correct 69 ms 2204 KB Output is correct
28 Correct 68 ms 2332 KB Output is correct
29 Correct 68 ms 2204 KB Output is correct
30 Correct 37 ms 1400 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct