Submission #23320

# Submission time Handle Problem Language Result Execution time Memory
23320 2017-05-06T09:24:21 Z duongthoi1999 Gap (APIO16_gap) C++14
100 / 100
76 ms 8280 KB
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> ii;
const int mod = (int) 1e9 + 7;
const ll inf = 1LL << 60;
const int maxn = (int) 1e5 + 5;
const ld eps = 1e-9;

vector<ll> a, b;
ll l[maxn], r[maxn];

ll subtask1(int N) {
    ll L = 0, R = inf;
    int pl = 0, pr = N - 1;
    a.resize(N);
    while (pl <= pr) {
        MinMax(L, R, &a[pl], &a[pr]);
        L = a[pl] + 1;
        R = a[pr] - 1;
        pl ++;
        pr --;
    }
    ll res = 1;
    rep(i, 1, N) res = max(res, a[i] - a[i - 1]);
    return res;
}

ll subtask2(int N) {
	a.assign(N + 1, 0);
	b.assign(N + 1, 0);
	MinMax(0, inf, &a[0], &a[N]);
	b[0] = a[0]; b[N] = a[N];
	ll len = a[N] - a[0] - 1;
    ll g = min(len, 1LL * N - 1);
    ll sg = len % g;
    ll bg = g - sg;
    l[0] = r[0] = a[0];
    a[g + 1] = a[N];
    b[g + 1] = b[N];
    rep(i, 1, g + 1) {
        l[i] = r[i - 1] + 1;
        if(i <= sg) r[i] = l[i] + (len / g) - 1;
        else r[i] = l[i] + (len / g);
        MinMax(l[i], r[i], &a[i], &b[i]);
    }
    ll res = 1;
    int j = 0;
    rep(i, 0, g + 2) {
        res = max(res, a[i] - b[j]);
        if(a[i] == -1 && b[i] == -1) continue;
        j = i;
    }
	return res;
}

ll findGap(int T, int N) {
    if(T == 1) return subtask1(N);
    if(T == 2) return subtask2(N);
}

Compilation message

gap.cpp: In function 'll subtask2(int)':
gap.cpp:46:8: warning: unused variable 'bg' [-Wunused-variable]
     ll bg = g - sg;
        ^
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:69:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6712 KB Output is correct
2 Correct 0 ms 6712 KB Output is correct
3 Correct 0 ms 6712 KB Output is correct
4 Correct 0 ms 6712 KB Output is correct
5 Correct 0 ms 6712 KB Output is correct
6 Correct 0 ms 6712 KB Output is correct
7 Correct 0 ms 6712 KB Output is correct
8 Correct 0 ms 6712 KB Output is correct
9 Correct 0 ms 6712 KB Output is correct
10 Correct 0 ms 6712 KB Output is correct
11 Correct 0 ms 6712 KB Output is correct
12 Correct 0 ms 6712 KB Output is correct
13 Correct 0 ms 6712 KB Output is correct
14 Correct 0 ms 6712 KB Output is correct
15 Correct 0 ms 6712 KB Output is correct
16 Correct 13 ms 6908 KB Output is correct
17 Correct 13 ms 6908 KB Output is correct
18 Correct 13 ms 6908 KB Output is correct
19 Correct 13 ms 6908 KB Output is correct
20 Correct 6 ms 6908 KB Output is correct
21 Correct 46 ms 7496 KB Output is correct
22 Correct 56 ms 7496 KB Output is correct
23 Correct 43 ms 7496 KB Output is correct
24 Correct 39 ms 7496 KB Output is correct
25 Correct 39 ms 7496 KB Output is correct
26 Correct 46 ms 7496 KB Output is correct
27 Correct 49 ms 7496 KB Output is correct
28 Correct 56 ms 7496 KB Output is correct
29 Correct 39 ms 7496 KB Output is correct
30 Correct 39 ms 7496 KB Output is correct
31 Correct 0 ms 6712 KB Output is correct
32 Correct 0 ms 6712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6712 KB Output is correct
2 Correct 0 ms 6712 KB Output is correct
3 Correct 0 ms 6712 KB Output is correct
4 Correct 0 ms 6712 KB Output is correct
5 Correct 0 ms 6712 KB Output is correct
6 Correct 0 ms 6712 KB Output is correct
7 Correct 0 ms 6712 KB Output is correct
8 Correct 0 ms 6712 KB Output is correct
9 Correct 0 ms 6712 KB Output is correct
10 Correct 0 ms 6712 KB Output is correct
11 Correct 0 ms 6712 KB Output is correct
12 Correct 0 ms 6712 KB Output is correct
13 Correct 0 ms 6712 KB Output is correct
14 Correct 0 ms 6712 KB Output is correct
15 Correct 0 ms 6712 KB Output is correct
16 Correct 16 ms 7104 KB Output is correct
17 Correct 19 ms 7104 KB Output is correct
18 Correct 16 ms 7104 KB Output is correct
19 Correct 16 ms 7104 KB Output is correct
20 Correct 6 ms 7104 KB Output is correct
21 Correct 73 ms 8280 KB Output is correct
22 Correct 66 ms 8280 KB Output is correct
23 Correct 59 ms 8280 KB Output is correct
24 Correct 73 ms 8280 KB Output is correct
25 Correct 69 ms 8280 KB Output is correct
26 Correct 69 ms 8280 KB Output is correct
27 Correct 76 ms 8280 KB Output is correct
28 Correct 73 ms 8280 KB Output is correct
29 Correct 73 ms 8280 KB Output is correct
30 Correct 39 ms 8280 KB Output is correct
31 Correct 0 ms 6712 KB Output is correct
32 Correct 0 ms 6712 KB Output is correct