# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
110756 |
2019-05-12T07:50:58 Z |
TAISA_ |
Gap (APIO16_gap) |
C++14 |
|
88 ms |
2740 KB |
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
/*void MinMax(ll l, ll r, ll& mi, ll& ma) {
cout << l << " " << r << endl;
cin >> mi >> ma;
}*/
ll findGap(int T, int n) {
ll INF = 1000000000000000000LL;
ll N = n;
ll mi, ma;
MinMax(0LL, INF, &mi, &ma);
if(N == ma - mi + 1LL) {
return 1LL;
}
if(T == 1) {
vector<ll> v1, v2;
v1.push_back(mi);
v2.push_back(ma);
for(int i = 0; i < N / 2 - 1; i++) {
MinMax(mi + 1LL, ma - 1LL, &mi, &ma);
v1.push_back(mi);
v2.push_back(ma);
}
if(N % 2) {
MinMax(mi + 1LL, ma - 1LL, &mi, &ma);
v1.push_back(mi);
}
reverse(v2.begin(), v2.end());
for(auto e : v2) {
v1.push_back(e);
}
ll res = 0;
for(int i = 1; i < N; i++) {
res = max(res, v1[i] - v1[i - 1]);
}
return res;
} else {
ll l = (ma - mi + 1LL) / N + 1LL, m = (ma - mi + 1LL) % N;
ll b = mi, res = 0, t = mi, s = 0, maa = ma;
bool f = false;
for(int i = 0; i < N - 1; i++) {
ll nl = l - (i >= m);
MinMax(t, t + nl - 1LL, &mi, &ma);
if(mi == -1) {
if(f) {
s += nl;
} else {
s += nl + (t - b);
f = true;
}
} else {
if(f) {
s += mi - t;
res = max(res, s);
s = 0;
f = false;
} else {
res = max(res, mi - b);
}
b = ma;
}
t += nl;
}
MinMax(t, maa - 1, &mi, &ma);
if(mi == -1) {
if(f) {
s += maa - t;
res = max(res, s);
} else {
res = max(res, maa - b);
}
} else {
if(f) {
s += mi - t;
res = max(res, s);
} else {
res = max(res, mi - b);
}
}
return res;
}
}
/*int main() {
cout << findGap(0, 4) << endl;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
320 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
428 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
356 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
356 KB |
Output is correct |
16 |
Correct |
14 ms |
1024 KB |
Output is correct |
17 |
Correct |
15 ms |
1024 KB |
Output is correct |
18 |
Correct |
18 ms |
1068 KB |
Output is correct |
19 |
Correct |
19 ms |
1060 KB |
Output is correct |
20 |
Correct |
15 ms |
1076 KB |
Output is correct |
21 |
Correct |
69 ms |
2672 KB |
Output is correct |
22 |
Correct |
54 ms |
2712 KB |
Output is correct |
23 |
Correct |
54 ms |
2676 KB |
Output is correct |
24 |
Correct |
52 ms |
2716 KB |
Output is correct |
25 |
Correct |
47 ms |
2716 KB |
Output is correct |
26 |
Correct |
68 ms |
2740 KB |
Output is correct |
27 |
Correct |
62 ms |
2716 KB |
Output is correct |
28 |
Correct |
53 ms |
2720 KB |
Output is correct |
29 |
Correct |
53 ms |
2732 KB |
Output is correct |
30 |
Correct |
51 ms |
2712 KB |
Output is correct |
31 |
Correct |
3 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
276 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
356 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
400 KB |
Output is correct |
14 |
Correct |
3 ms |
364 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
20 ms |
604 KB |
Output is correct |
17 |
Correct |
20 ms |
580 KB |
Output is correct |
18 |
Correct |
19 ms |
588 KB |
Output is correct |
19 |
Correct |
18 ms |
588 KB |
Output is correct |
20 |
Correct |
10 ms |
588 KB |
Output is correct |
21 |
Correct |
77 ms |
1172 KB |
Output is correct |
22 |
Correct |
72 ms |
1168 KB |
Output is correct |
23 |
Correct |
72 ms |
1232 KB |
Output is correct |
24 |
Correct |
74 ms |
1048 KB |
Output is correct |
25 |
Correct |
68 ms |
1156 KB |
Output is correct |
26 |
Correct |
73 ms |
1172 KB |
Output is correct |
27 |
Correct |
71 ms |
1048 KB |
Output is correct |
28 |
Correct |
78 ms |
1156 KB |
Output is correct |
29 |
Correct |
88 ms |
1172 KB |
Output is correct |
30 |
Correct |
54 ms |
1140 KB |
Output is correct |
31 |
Correct |
2 ms |
356 KB |
Output is correct |
32 |
Correct |
2 ms |
392 KB |
Output is correct |