# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
377852 |
2021-03-15T10:56:04 Z |
blue |
Gap (APIO16_gap) |
C++17 |
|
76 ms |
2852 KB |
#include "gap.h"
#include <algorithm>
#include <cmath>
using namespace std;
long long findGap(int T, int N)
{
long long res = 0;
if(T == 1)
{
long long s, t;
long long mn;
long long mx;
s = 0;
t = 1000'000'000'000'000'000LL;
if(N % 2 == 0)
{
MinMax(s, t, &mn, &mx);
s = mn + 1;
t = mx - 1;
for(int i = 2; i <= N/2; i++)
{
MinMax(s, t, &mn, &mx);
res = max(res, mn - (s-1));
res = max(res, (t+1) - mx);
s = mn + 1;
t = mx - 1;
}
res = max(res, mx - mn);
}
else
{
MinMax(s, t, &mn, &mx);
s = mn + 1;
t = mx - 1;
for(int i = 2; i <= (N+1)/2; i++)
{
MinMax(s, t, &mn, &mx);
res = max(res, mn - (s-1));
res = max(res, (t+1) - mx);
s = mn + 1;
t = mx - 1;
}
}
}
else if(T == 2)
{
long long s, t;
long long mn, mx;
s = 0;
t = 1'000'000'000'000'000'000LL;
MinMax(s, t, &mn, &mx); //M += N+1
long long a1 = mn, aN = mx;
long long gap = (aN-a1)/(N-1) + ((aN-a1) % (N-1) != 0);
vector<long long> L, R;
L.push_back(a1);
R.push_back(a1);
for(long long x = a1+1; x < aN; x += gap)
{
MinMax(x, std::min(x+gap-1, aN-1), &mn, &mx);
if (mn != -1)
{
L.push_back(mn);
R.push_back(mx);
}
}
L.push_back(aN);
R.push_back(aN);
for(int i = 0; i < L.size()-1; i++)
{
res = max(res, L[i+1] - R[i]);
}
}
return res;
}
Compilation message
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:79:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i = 0; i < L.size()-1; i++)
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
11 ms |
492 KB |
Output is correct |
17 |
Correct |
14 ms |
492 KB |
Output is correct |
18 |
Correct |
11 ms |
492 KB |
Output is correct |
19 |
Correct |
11 ms |
492 KB |
Output is correct |
20 |
Correct |
9 ms |
492 KB |
Output is correct |
21 |
Correct |
44 ms |
1140 KB |
Output is correct |
22 |
Correct |
43 ms |
1068 KB |
Output is correct |
23 |
Correct |
51 ms |
1260 KB |
Output is correct |
24 |
Correct |
46 ms |
1164 KB |
Output is correct |
25 |
Correct |
39 ms |
1132 KB |
Output is correct |
26 |
Correct |
46 ms |
1080 KB |
Output is correct |
27 |
Correct |
44 ms |
1132 KB |
Output is correct |
28 |
Correct |
44 ms |
1132 KB |
Output is correct |
29 |
Correct |
47 ms |
1292 KB |
Output is correct |
30 |
Correct |
47 ms |
1132 KB |
Output is correct |
31 |
Correct |
0 ms |
364 KB |
Output is correct |
32 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
17 ms |
876 KB |
Output is correct |
17 |
Correct |
15 ms |
876 KB |
Output is correct |
18 |
Correct |
16 ms |
876 KB |
Output is correct |
19 |
Correct |
18 ms |
876 KB |
Output is correct |
20 |
Correct |
7 ms |
492 KB |
Output is correct |
21 |
Correct |
67 ms |
2348 KB |
Output is correct |
22 |
Correct |
61 ms |
2256 KB |
Output is correct |
23 |
Correct |
62 ms |
2192 KB |
Output is correct |
24 |
Correct |
73 ms |
2340 KB |
Output is correct |
25 |
Correct |
60 ms |
2852 KB |
Output is correct |
26 |
Correct |
65 ms |
2192 KB |
Output is correct |
27 |
Correct |
62 ms |
2192 KB |
Output is correct |
28 |
Correct |
69 ms |
2192 KB |
Output is correct |
29 |
Correct |
76 ms |
2192 KB |
Output is correct |
30 |
Correct |
33 ms |
1516 KB |
Output is correct |
31 |
Correct |
0 ms |
364 KB |
Output is correct |
32 |
Correct |
0 ms |
364 KB |
Output is correct |