# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
138421 |
2019-07-29T22:03:49 Z |
MetB |
Shortcut (IOI16_shortcut) |
C++14 |
|
2 ms |
380 KB |
#include <algorithm>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <vector>
#include <string>
#include <bitset>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7, INF = 1e18 + 1;
using namespace std;
ll x[1000000], to_diff[1000000], n, c;
vector <int> d;
pair <int, int> diff[1000000], sum[1000000];
struct BIT
{
ll t1[1000000], t2[1000000];
void update (ll x, ll d)
{
for (; x <= n; x |= (x + 1))
{
t1[x] = max (t1[x], d);
t2[x] = min (t2[x], d);
}
}
pair <ll, ll> get (ll r)
{
ll mx = -INF, mn = INF;
for (;r >= 0; r = (r & (r + 1)) - 1)
{
mx = max (mx, t1[r]);
mn = min (mn, t2[r]);
}
return {mn, mx};
}
void clear ()
{
for (ll i = 0; i < n; i++)
{
t1[i] = -INF;
t2[i] = INF;
}
}
} t_diff, t_sum;
bool check (ll k)
{
t_diff.clear ();
t_sum.clear ();
vector <ll> v (n);
ll j = 0;
for (ll i = 0; i < n; i++)
{
while (j < n && diff[j].first < sum[i].first - k)
j++;
ll cur = sum[i].second;
v[cur] = j;
}
ll min_y_plus_z = -INF, max_y_plus_z = INF;
ll min_y_minus_z = -INF, max_y_minus_z = INF;
for (ll i = 0; i < n; i++)
{
pair <ll, ll> diff_border = t_diff.get (v[i] - 1);
pair <ll, ll> sum_border = t_sum.get (v[i] - 1);
if (diff_border.first != INF)
{
min_y_plus_z = max (min_y_plus_z, sum_border.second + x[i] + d[i] - k + c);
max_y_plus_z = min (max_y_plus_z, diff_border.first + (x[i] - d[i]) + k - c);
min_y_minus_z = max (min_y_minus_z, x[i] + d[i] - diff_border.first - k + c);
max_y_minus_z = min (max_y_minus_z, (x[i] - d[i]) - sum_border.second + k - c);
}
t_diff.update (to_diff[i], x[i] - d[i]);
t_sum.update (to_diff[i], x[i] + d[i]);
}
if (min_y_plus_z > max_y_plus_z) return false;
if (min_y_minus_z > max_y_minus_z) return false;
for (ll i = 0; i < n; i++)
for (ll j = 0; j < i; j++)
if (min_y_plus_z <= x[i] + x[j] && x[i] + x[j] <= max_y_plus_z &&
min_y_minus_z <= x[i] - x[j] && x[i] - x[j] <= max_y_minus_z)
return true;
return false;
}
ll find_shortcut (int n, vector <int> l, vector <int> d, int c)
{
::n = n;
::c = c;
::d = d;
for (ll i = 1; i < n; i++)
{
x[i] = x[i-1] + l[i-1];
}
for (ll i = 0; i < n; i++)
{
sum[i] = {x[i] + d[i], i};
diff[i] = {x[i] - d[i], i};
}
sort (sum, sum + n);
sort (diff, diff + n);
for (ll i = 0; i < n; i++)
to_diff[diff[i].second] = i;
ll L = 0, R = INF;
while (L < R)
{
ll mid = (L + R) / 2;
if (check (mid)) R = mid;
else L = mid + 1;
}
return L;
}
/*int main ()
{
int n, c;
cin >> n;
vector <int> l (n - 1), d (n);
for (int i = 0; i < n - 1; i++)
scanf ("%d", &l[i]);
for (int i = 0; i < n; i++)
scanf ("%d", &d[i]);
cin >> c;
cout << find_shortcut (n, l, d, c);
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
380 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
376 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
376 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
376 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
376 KB |
n = 2, 3000000000 is a correct answer |
12 |
Incorrect |
2 ms |
376 KB |
n = 3, incorrect answer: jury 3000000000 vs contestant 2000000001 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
380 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
376 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
376 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
376 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
376 KB |
n = 2, 3000000000 is a correct answer |
12 |
Incorrect |
2 ms |
376 KB |
n = 3, incorrect answer: jury 3000000000 vs contestant 2000000001 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
380 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
376 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
376 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
376 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
376 KB |
n = 2, 3000000000 is a correct answer |
12 |
Incorrect |
2 ms |
376 KB |
n = 3, incorrect answer: jury 3000000000 vs contestant 2000000001 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
380 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
376 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
376 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
376 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
376 KB |
n = 2, 3000000000 is a correct answer |
12 |
Incorrect |
2 ms |
376 KB |
n = 3, incorrect answer: jury 3000000000 vs contestant 2000000001 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
380 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
376 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
376 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
376 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
376 KB |
n = 2, 3000000000 is a correct answer |
12 |
Incorrect |
2 ms |
376 KB |
n = 3, incorrect answer: jury 3000000000 vs contestant 2000000001 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
380 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
376 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
376 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
376 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
376 KB |
n = 2, 3000000000 is a correct answer |
12 |
Incorrect |
2 ms |
376 KB |
n = 3, incorrect answer: jury 3000000000 vs contestant 2000000001 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
380 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
376 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
376 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
376 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
376 KB |
n = 2, 3000000000 is a correct answer |
12 |
Incorrect |
2 ms |
376 KB |
n = 3, incorrect answer: jury 3000000000 vs contestant 2000000001 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
380 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
376 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
376 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
2 ms |
376 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
376 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
376 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
376 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
2 ms |
376 KB |
n = 2, 3000000000 is a correct answer |
12 |
Incorrect |
2 ms |
376 KB |
n = 3, incorrect answer: jury 3000000000 vs contestant 2000000001 |
13 |
Halted |
0 ms |
0 KB |
- |