Submission #25597

# Submission time Handle Problem Language Result Execution time Memory
25597 2017-06-23T07:16:12 Z kajebiii Gap (APIO16_gap) C++14
89.5346 / 100
93 ms 6588 KB
#include "gap.h"

#include <algorithm>
#include <stdio.h>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;


const ll MINV = 0, MAXV = 1e18;
const int MAX_N = 1e5 + 100;

ll minV, maxV;

ll Nr[MAX_N][2], Ans[MAX_N];
long long findGap(int T, int N)
{
    if(T == 1) {
        ll ans = 0;
        minV = MINV, maxV = MAXV;        
        int li = 0, ri = N-1;
        for(int i=0; i<(N+1)/2; i++) {
            ll l, r;
            MinMax(minV, maxV, &l, &r);
            Ans[li++] = l;
            Ans[ri--] = r;
            minV = l+1; maxV = r-1;
        }
        for(int i=0; i+1<N; i++)
            ans = max(ans, Ans[i+1] - Ans[i]);
        return ans;
    }
    if(T == 2) {
        MinMax(MINV, MAXV, &minV, &maxV);
        if(N == 2) return maxV - minV;

        ll diff = (maxV-1 - (minV+1) + N-3) / (N-2);
        ll ans = 0, lastR = minV;
        bool isBlank = false;
        for(int i=0; i<N-2; i++) {
            ll l = min(maxV-1, minV+1 + i * diff);
            ll r = min(maxV-1, minV+1 + (i+1) * diff - 1);

            MinMax(l, r, &Nr[i][0], &Nr[i][1]);
//            printf("%lld %lld -> %lld %lld\n", l, r, Nr[i][0], Nr[i][1]);
            if(Nr[i][0] >= 0) {
                if(lastR != -1) ans = max(ans, Nr[i][0] - lastR);
                lastR = Nr[i][1];
            }else{
                isBlank = true;
            }
        }
        ans = max(ans, maxV - lastR);
        return ans;
    }
	return 0;
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:49:14: warning: variable 'isBlank' set but not used [-Wunused-but-set-variable]
         bool isBlank = false;
              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6588 KB Output is correct
2 Correct 0 ms 6588 KB Output is correct
3 Correct 0 ms 6588 KB Output is correct
4 Correct 0 ms 6588 KB Output is correct
5 Correct 0 ms 6588 KB Output is correct
6 Correct 0 ms 6588 KB Output is correct
7 Correct 0 ms 6588 KB Output is correct
8 Correct 0 ms 6588 KB Output is correct
9 Correct 0 ms 6588 KB Output is correct
10 Correct 0 ms 6588 KB Output is correct
11 Correct 0 ms 6588 KB Output is correct
12 Correct 0 ms 6588 KB Output is correct
13 Correct 0 ms 6588 KB Output is correct
14 Correct 0 ms 6588 KB Output is correct
15 Correct 0 ms 6588 KB Output is correct
16 Correct 19 ms 6588 KB Output is correct
17 Correct 13 ms 6588 KB Output is correct
18 Correct 13 ms 6588 KB Output is correct
19 Correct 6 ms 6588 KB Output is correct
20 Correct 13 ms 6588 KB Output is correct
21 Correct 63 ms 6588 KB Output is correct
22 Correct 59 ms 6588 KB Output is correct
23 Correct 56 ms 6588 KB Output is correct
24 Correct 59 ms 6588 KB Output is correct
25 Correct 46 ms 6588 KB Output is correct
26 Correct 56 ms 6588 KB Output is correct
27 Correct 49 ms 6588 KB Output is correct
28 Correct 63 ms 6588 KB Output is correct
29 Correct 53 ms 6588 KB Output is correct
30 Correct 29 ms 6588 KB Output is correct
31 Correct 0 ms 6588 KB Output is correct
32 Correct 0 ms 6588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6588 KB Output is correct
2 Correct 0 ms 6588 KB Output is correct
3 Correct 0 ms 6588 KB Output is correct
4 Correct 0 ms 6588 KB Output is correct
5 Correct 0 ms 6588 KB Output is correct
6 Correct 0 ms 6588 KB Output is correct
7 Correct 0 ms 6588 KB Output is correct
8 Correct 0 ms 6588 KB Output is correct
9 Correct 0 ms 6588 KB Output is correct
10 Correct 0 ms 6588 KB Output is correct
11 Correct 0 ms 6588 KB Output is correct
12 Correct 0 ms 6588 KB Output is correct
13 Correct 0 ms 6588 KB Output is correct
14 Correct 0 ms 6588 KB Output is correct
15 Correct 0 ms 6588 KB Output is correct
16 Correct 19 ms 6588 KB Output is correct
17 Correct 16 ms 6588 KB Output is correct
18 Correct 13 ms 6588 KB Output is correct
19 Correct 16 ms 6588 KB Output is correct
20 Partially correct 6 ms 6588 KB Partially correct
21 Correct 69 ms 6588 KB Output is correct
22 Correct 73 ms 6588 KB Output is correct
23 Correct 63 ms 6588 KB Output is correct
24 Correct 83 ms 6588 KB Output is correct
25 Correct 89 ms 6588 KB Output is correct
26 Correct 93 ms 6588 KB Output is correct
27 Correct 73 ms 6588 KB Output is correct
28 Correct 63 ms 6588 KB Output is correct
29 Correct 83 ms 6588 KB Output is correct
30 Partially correct 33 ms 6588 KB Partially correct
31 Correct 0 ms 6588 KB Output is correct
32 Correct 0 ms 6588 KB Output is correct