# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
61202 |
2018-07-25T11:06:42 Z |
Eae02 |
Gap (APIO16_gap) |
C++14 |
|
115 ms |
2300 KB |
#include "gap.h"
#include <bits/stdc++.h>
using ll = long long;
ll gMaxDiff = 0;
std::set<ll> found;
int targetCount;
bool checkDone(ll min, ll max)
{
found.insert(min);
found.insert(max);
if (found.size() >= targetCount)
{
gMaxDiff = std::max(gMaxDiff, max - min);
return true;
}
return false;
}
void maxDiff(ll min, ll max)
{
if (checkDone(min, max))
return;
if (max == min + 1)
{
gMaxDiff = std::max(gMaxDiff, max - min);
return;
}
ll mid = min + (max - min) / 2;
ll s1Min, s1Max;
MinMax(min + 1, mid - 1, &s1Min, &s1Max);
bool s1Pop = s1Min != -1;
ll s2Min, s2Max;
MinMax(mid, max - 1, &s2Min, &s2Max);
bool s2Pop = s2Min != -1;
if (s1Pop && s2Pop)
{
gMaxDiff = std::max(gMaxDiff, s2Min - s1Max);
gMaxDiff = std::max(gMaxDiff, s1Min - min);
gMaxDiff = std::max(gMaxDiff, max - s2Max);
}
else if (!s1Pop && s2Pop)
{
gMaxDiff = std::max(gMaxDiff, s2Min - min);
gMaxDiff = std::max(gMaxDiff, max - s2Max);
}
else if (s1Pop && !s2Pop)
{
gMaxDiff = std::max(gMaxDiff, s1Min - min);
gMaxDiff = std::max(gMaxDiff, max - s1Max);
}
else if (!s1Pop && !s2Pop)
{
gMaxDiff = std::max(gMaxDiff, max - min);
}
if (s1Pop && checkDone(s1Min, s1Max))
return;
if (s2Pop && checkDone(s2Min, s2Max))
return;
ll s1Diff = s1Max - s1Min;
ll s2Diff = s2Max - s2Min;
bool travS1 = s1Pop && s1Diff > gMaxDiff;
bool travS2 = s2Pop && s2Diff > gMaxDiff;
if (travS1 && travS2)
{
if (s1Diff > s2Diff)
{
maxDiff(s1Min, s1Max);
if (s2Diff > gMaxDiff)
maxDiff(s2Min, s2Max);
}
else
{
maxDiff(s2Min, s2Max);
if (s1Diff > gMaxDiff)
maxDiff(s1Min, s1Max);
}
}
else
{
if (travS1)
maxDiff(s1Min, s1Max);
if (travS2)
maxDiff(s2Min, s2Max);
}
}
long long findGap(int T, int N)
{
if (T == 1)
{
ll min = 0;
ll max = 1000000000000000000;
std::vector<ll> numbers(N);
for (int i = 0; 2 * i < N; i++)
{
ll nextMin, nextMax;
MinMax(min, max, &nextMin, &nextMax);
numbers[i] = nextMin;
numbers[numbers.size() - i - 1] = nextMax;
min = nextMin + 1;
max = nextMax - 1;
}
for (int i = 1; i < N; i++)
{
gMaxDiff = std::max(gMaxDiff, numbers[i] - numbers[i - 1]);
}
}
else
{
ll min, max;
MinMax(0, 1000000000000000000, &min, &max);
targetCount = N;
ll step = std::ceil((max - min) / (double)(N - 2));
ll prev = min;
for (ll i = min; i < max; i += step)
{
ll nMin, nMax;
MinMax(i + 1, i + step, &nMin, &nMax);
//std::cout << nMin << " " << nMax << ", " << nMin - prev << std::endl;
if (nMin == -1)
continue;
gMaxDiff = std::max(gMaxDiff, nMin - prev);
prev = nMax;
}
gMaxDiff = std::max(gMaxDiff, max - prev);
//maxDiff(min, max);
}
return gMaxDiff;
}
Compilation message
gap.cpp: In function 'bool checkDone(ll, ll)':
gap.cpp:16:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (found.size() >= targetCount)
~~~~~~~~~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
396 KB |
Output is correct |
3 |
Correct |
3 ms |
416 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
3 ms |
624 KB |
Output is correct |
9 |
Correct |
2 ms |
624 KB |
Output is correct |
10 |
Correct |
2 ms |
624 KB |
Output is correct |
11 |
Correct |
4 ms |
624 KB |
Output is correct |
12 |
Correct |
4 ms |
636 KB |
Output is correct |
13 |
Correct |
4 ms |
636 KB |
Output is correct |
14 |
Correct |
4 ms |
716 KB |
Output is correct |
15 |
Correct |
4 ms |
716 KB |
Output is correct |
16 |
Correct |
21 ms |
1020 KB |
Output is correct |
17 |
Correct |
18 ms |
1020 KB |
Output is correct |
18 |
Correct |
18 ms |
1020 KB |
Output is correct |
19 |
Correct |
17 ms |
1020 KB |
Output is correct |
20 |
Correct |
13 ms |
1020 KB |
Output is correct |
21 |
Correct |
79 ms |
2172 KB |
Output is correct |
22 |
Correct |
79 ms |
2216 KB |
Output is correct |
23 |
Correct |
65 ms |
2216 KB |
Output is correct |
24 |
Correct |
83 ms |
2216 KB |
Output is correct |
25 |
Correct |
60 ms |
2300 KB |
Output is correct |
26 |
Correct |
65 ms |
2300 KB |
Output is correct |
27 |
Correct |
62 ms |
2300 KB |
Output is correct |
28 |
Correct |
69 ms |
2300 KB |
Output is correct |
29 |
Correct |
88 ms |
2300 KB |
Output is correct |
30 |
Correct |
50 ms |
2300 KB |
Output is correct |
31 |
Correct |
3 ms |
2300 KB |
Output is correct |
32 |
Correct |
3 ms |
2300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
2300 KB |
Execution failed because the return code was nonzero |
2 |
Correct |
3 ms |
2300 KB |
Output is correct |
3 |
Correct |
3 ms |
2300 KB |
Output is correct |
4 |
Correct |
3 ms |
2300 KB |
Output is correct |
5 |
Correct |
3 ms |
2300 KB |
Output is correct |
6 |
Correct |
3 ms |
2300 KB |
Output is correct |
7 |
Correct |
3 ms |
2300 KB |
Output is correct |
8 |
Correct |
3 ms |
2300 KB |
Output is correct |
9 |
Correct |
2 ms |
2300 KB |
Output is correct |
10 |
Correct |
2 ms |
2300 KB |
Output is correct |
11 |
Correct |
4 ms |
2300 KB |
Output is correct |
12 |
Correct |
4 ms |
2300 KB |
Output is correct |
13 |
Correct |
4 ms |
2300 KB |
Output is correct |
14 |
Correct |
3 ms |
2300 KB |
Output is correct |
15 |
Correct |
4 ms |
2300 KB |
Output is correct |
16 |
Correct |
21 ms |
2300 KB |
Output is correct |
17 |
Correct |
22 ms |
2300 KB |
Output is correct |
18 |
Correct |
29 ms |
2300 KB |
Output is correct |
19 |
Correct |
21 ms |
2300 KB |
Output is correct |
20 |
Correct |
15 ms |
2300 KB |
Output is correct |
21 |
Correct |
105 ms |
2300 KB |
Output is correct |
22 |
Correct |
106 ms |
2300 KB |
Output is correct |
23 |
Correct |
96 ms |
2300 KB |
Output is correct |
24 |
Correct |
115 ms |
2300 KB |
Output is correct |
25 |
Correct |
76 ms |
2300 KB |
Output is correct |
26 |
Correct |
104 ms |
2300 KB |
Output is correct |
27 |
Correct |
88 ms |
2300 KB |
Output is correct |
28 |
Correct |
101 ms |
2300 KB |
Output is correct |
29 |
Correct |
84 ms |
2300 KB |
Output is correct |
30 |
Correct |
47 ms |
2300 KB |
Output is correct |
31 |
Correct |
2 ms |
2300 KB |
Output is correct |
32 |
Correct |
2 ms |
2300 KB |
Output is correct |