Submission #396244

# Submission time Handle Problem Language Result Execution time Memory
396244 2021-04-29T15:28:19 Z giorgikob Gap (APIO16_gap) C++14
100 / 100
71 ms 1180 KB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;

//#include "game.h"

#include "gap.h"

ll answer = 0;
long long findGap(int T, int N)
{
    ll l = -1, r = 1e18; r++;
    ll cnt = 0;
    int calls = 0;
    ll len = -1;
    if(T == 1){
        while(true){
            ll new_l,new_r;
            if(len != -1){
                if((r-l) < len/N) break;
            }
            cnt++;
            if(answer >= r-l) break;
            if(cnt > (N+1)/2){
                if(l != r){
                    answer = max(answer,r-l);
                }
                break;
            }
            if(l+1 > r-1){
                if(l == r) break;
                answer = max(answer,r-l);
                break;
            }
            MinMax(l+1,r-1,&new_l,&new_r);
            calls++;
            if(new_l == -1){
                answer = max(answer,r-l);
                break;
            } else {
                if(cnt > 1)answer = max(answer, max(new_l-l,r-new_r)); else len = new_r-new_l;
                l = new_l;
                r = new_r;
            }
        }
    } else {
        ll last = -1;
        MinMax(0,1e18,&l,&r);
        ll k = (r-l+1)/N;
        if((r-l+1)%N) k++;
        if(r-l+1 == N){
            return N;
        }
        assert(k != 1);
        last = l;
        for(ll i = l; i <= r; i += k){
            ll a,b;
            ll askl = i;
            if(i == l) askl = l+1;
            MinMax(askl,min(i+k-1,r),&a,&b);
            if(a == -1){
                continue;
            }
            answer = max(answer,b-a);
            if(last != -1){
                answer = max(answer,a-last);
            }
            last = b;
        }
    }

	return answer;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 200 KB Output is correct
16 Correct 11 ms 456 KB Output is correct
17 Correct 13 ms 456 KB Output is correct
18 Correct 12 ms 460 KB Output is correct
19 Correct 12 ms 424 KB Output is correct
20 Correct 9 ms 456 KB Output is correct
21 Correct 45 ms 1072 KB Output is correct
22 Correct 46 ms 1088 KB Output is correct
23 Correct 45 ms 1024 KB Output is correct
24 Correct 46 ms 1076 KB Output is correct
25 Correct 42 ms 1148 KB Output is correct
26 Correct 48 ms 1052 KB Output is correct
27 Correct 45 ms 1056 KB Output is correct
28 Correct 44 ms 988 KB Output is correct
29 Correct 44 ms 1012 KB Output is correct
30 Correct 33 ms 1076 KB Output is correct
31 Correct 1 ms 200 KB Output is correct
32 Correct 1 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 2 ms 328 KB Output is correct
16 Correct 15 ms 456 KB Output is correct
17 Correct 17 ms 504 KB Output is correct
18 Correct 17 ms 504 KB Output is correct
19 Correct 17 ms 456 KB Output is correct
20 Correct 8 ms 456 KB Output is correct
21 Correct 70 ms 976 KB Output is correct
22 Correct 71 ms 1180 KB Output is correct
23 Correct 62 ms 1056 KB Output is correct
24 Correct 68 ms 992 KB Output is correct
25 Correct 68 ms 1052 KB Output is correct
26 Correct 66 ms 988 KB Output is correct
27 Correct 67 ms 1076 KB Output is correct
28 Correct 63 ms 1056 KB Output is correct
29 Correct 65 ms 1032 KB Output is correct
30 Correct 34 ms 1044 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 200 KB Output is correct