# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
388579 |
2021-04-12T07:40:09 Z |
Keshi |
Shortcut (IOI16_shortcut) |
C++17 |
|
12 ms |
19148 KB |
//In the name of God
#include <bits/stdc++.h>
#include "shortcut.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
#define lc (id << 1)
#define rc (lc | 1)
struct node{
ll mxr, mxl, mx;
node(){
mxr = mxl = mx = -inf;
}
};
ll n, ps[maxn], d[maxn];
node seg[maxn << 2];
node mrg(node l, node r){
if(l.mx == -inf) return r;
if(r.mx == -inf) return l;
node nd;
nd.mx = max({l.mx, r.mx, l.mxl + r.mxr});
nd.mxl = max(l.mxl, r.mxl);
nd.mxr = max(l.mxr, r.mxr);
return nd;
}
void bld(ll id, ll s, ll e){
if(e - s == 1){
seg[id].mx = d[s];
seg[id].mxl = d[s] - ps[s];
seg[id].mxr = d[s] + ps[s];
return;
}
ll mid = (s + e) >> 1;
bld(lc, s, mid);
bld(rc, mid, e);
seg[id] = mrg(seg[lc], seg[rc]);
return;
}
node get(ll id, ll s, ll e, ll l, ll r){
if(r <= s || e <= l) return node();
if(l <= s && e <= r) return seg[id];
ll mid = (s + e) >> 1;
return mrg(get(lc, s, mid, l, r), get(rc, mid, e, l, r));
}
node get(ll l, ll r){
/*node nd;
nd.mx = d[l];
nd.mxl = d[l] - ps[l];
nd.mxr = d[l] + ps[l];
for(ll i = l + 1; i < r; i++){
nd.mx = max(nd.mx, nd.mxl + d[i] + ps[i]);
nd.mxl = max(nd.mxl, d[i] - ps[i]);
nd.mxr = max(nd.mxr, d[i] + ps[i]);
}
return nd;*/
return get(1, 0, n, l, r);
}
long long find_shortcut(int N, vector<int> l, vector<int> D, int c){
n = N;
for(ll i = 0; i < n; i++){
d[i] = D[i];
ps[i + 1] = ps[i] + l[i];
}
bld(1, 0, n);
ll ans = get(0, n).mx;
for(ll i = 0; i < n; i++){
for(ll j = i + 1; j < n; j++){
ll C = ps[j] - ps[i] + c;
ll x = get(0, i + 1).mxl + get(j, n).mxr - max(0ll, (ps[j] - ps[i]) - c);
// cout << "! " << x << "\n";
x = max(x, get(0, i + 1).mx);
// cout << "! " << x << "\n";
x = max(x, get(j, n).mx);
// cout << "! " << x << "\n";
// cout << "^ " << C << "\n";
ll ptr = i;
ll mx1 = max((ll)c, C - c), mx2 = max((ll)c, C - c);
for(ll k = i; k < j; k++){
mx1 = max(mx1, d[k] + min(ps[k] - ps[i], C + ps[i] - ps[k]));
// cout << "! " << min(ps[k] - ps[i], C + ps[i] - ps[k]) << " " <<min(ps[j] - ps[k], C + ps[k] - ps[j]) << "\n";
mx2 = max(mx2, d[k] + min(ps[j] - ps[k], C + ps[k] - ps[j]));
while(ptr <= j && ps[ptr] - ps[k] < C + ps[k] - ps[ptr]) ptr++;
// cout << "# " << k << " " << ptr << "\n";
x = max(x, d[k] - ps[k] + get(k + 1, ptr).mxr);
// cout << "! " << x << "\n";
x = max(x, C + d[k] + ps[k] + get(ptr, j + 1).mxl);
// cout << "! " << x << "\n";
}
x = max(x, mx2 + get(j + 1, n).mxr - ps[j]);
// cout << "! " << x << "\n";
// cout << mx1 << " " << get(0, i).mxl + ps[i] << "\n";
x = max(x, mx1 + get(0, i).mxl + ps[i]);
// cout << "! " << x << "\n";
// if(x == 100) cout << "$ " << i << " " << j << "\n";
ans = min(ans, x);
}
}
return ans;
}
/*int main(){
fast_io;
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19080 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
10 ms |
19020 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
10 ms |
19020 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
9 ms |
19012 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
9 ms |
19020 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
10 ms |
19024 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
9 ms |
19020 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
11 ms |
19020 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
10 ms |
19020 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
9 ms |
19072 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
10 ms |
19148 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
9 ms |
19020 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
9 ms |
19020 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
9 ms |
19020 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
10 ms |
19072 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
10 ms |
19020 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
11 ms |
19100 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
10 ms |
19104 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
10 ms |
19024 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
9 ms |
19020 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
9 ms |
19104 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
9 ms |
19108 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
12 ms |
19104 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
11 ms |
19020 KB |
n = 10, incorrect answer: jury 336 vs contestant 364 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19080 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
10 ms |
19020 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
10 ms |
19020 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
9 ms |
19012 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
9 ms |
19020 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
10 ms |
19024 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
9 ms |
19020 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
11 ms |
19020 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
10 ms |
19020 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
9 ms |
19072 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
10 ms |
19148 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
9 ms |
19020 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
9 ms |
19020 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
9 ms |
19020 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
10 ms |
19072 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
10 ms |
19020 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
11 ms |
19100 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
10 ms |
19104 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
10 ms |
19024 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
9 ms |
19020 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
9 ms |
19104 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
9 ms |
19108 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
12 ms |
19104 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
11 ms |
19020 KB |
n = 10, incorrect answer: jury 336 vs contestant 364 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19080 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
10 ms |
19020 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
10 ms |
19020 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
9 ms |
19012 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
9 ms |
19020 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
10 ms |
19024 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
9 ms |
19020 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
11 ms |
19020 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
10 ms |
19020 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
9 ms |
19072 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
10 ms |
19148 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
9 ms |
19020 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
9 ms |
19020 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
9 ms |
19020 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
10 ms |
19072 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
10 ms |
19020 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
11 ms |
19100 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
10 ms |
19104 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
10 ms |
19024 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
9 ms |
19020 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
9 ms |
19104 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
9 ms |
19108 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
12 ms |
19104 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
11 ms |
19020 KB |
n = 10, incorrect answer: jury 336 vs contestant 364 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19080 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
10 ms |
19020 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
10 ms |
19020 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
9 ms |
19012 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
9 ms |
19020 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
10 ms |
19024 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
9 ms |
19020 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
11 ms |
19020 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
10 ms |
19020 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
9 ms |
19072 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
10 ms |
19148 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
9 ms |
19020 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
9 ms |
19020 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
9 ms |
19020 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
10 ms |
19072 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
10 ms |
19020 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
11 ms |
19100 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
10 ms |
19104 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
10 ms |
19024 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
9 ms |
19020 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
9 ms |
19104 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
9 ms |
19108 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
12 ms |
19104 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
11 ms |
19020 KB |
n = 10, incorrect answer: jury 336 vs contestant 364 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19080 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
10 ms |
19020 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
10 ms |
19020 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
9 ms |
19012 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
9 ms |
19020 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
10 ms |
19024 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
9 ms |
19020 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
11 ms |
19020 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
10 ms |
19020 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
9 ms |
19072 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
10 ms |
19148 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
9 ms |
19020 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
9 ms |
19020 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
9 ms |
19020 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
10 ms |
19072 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
10 ms |
19020 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
11 ms |
19100 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
10 ms |
19104 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
10 ms |
19024 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
9 ms |
19020 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
9 ms |
19104 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
9 ms |
19108 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
12 ms |
19104 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
11 ms |
19020 KB |
n = 10, incorrect answer: jury 336 vs contestant 364 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19080 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
10 ms |
19020 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
10 ms |
19020 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
9 ms |
19012 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
9 ms |
19020 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
10 ms |
19024 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
9 ms |
19020 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
11 ms |
19020 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
10 ms |
19020 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
9 ms |
19072 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
10 ms |
19148 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
9 ms |
19020 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
9 ms |
19020 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
9 ms |
19020 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
10 ms |
19072 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
10 ms |
19020 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
11 ms |
19100 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
10 ms |
19104 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
10 ms |
19024 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
9 ms |
19020 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
9 ms |
19104 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
9 ms |
19108 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
12 ms |
19104 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
11 ms |
19020 KB |
n = 10, incorrect answer: jury 336 vs contestant 364 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19080 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
10 ms |
19020 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
10 ms |
19020 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
9 ms |
19012 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
9 ms |
19020 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
10 ms |
19024 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
9 ms |
19020 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
11 ms |
19020 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
10 ms |
19020 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
9 ms |
19072 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
10 ms |
19148 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
9 ms |
19020 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
9 ms |
19020 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
9 ms |
19020 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
10 ms |
19072 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
10 ms |
19020 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
11 ms |
19100 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
10 ms |
19104 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
10 ms |
19024 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
9 ms |
19020 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
9 ms |
19104 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
9 ms |
19108 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
12 ms |
19104 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
11 ms |
19020 KB |
n = 10, incorrect answer: jury 336 vs contestant 364 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19080 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
10 ms |
19020 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
10 ms |
19020 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
9 ms |
19012 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
9 ms |
19020 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
10 ms |
19024 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
9 ms |
19020 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
11 ms |
19020 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
10 ms |
19020 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
9 ms |
19072 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
10 ms |
19148 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
9 ms |
19020 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
9 ms |
19020 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
9 ms |
19020 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
10 ms |
19072 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
10 ms |
19020 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
11 ms |
19100 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
10 ms |
19104 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
10 ms |
19024 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
9 ms |
19020 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
9 ms |
19104 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
9 ms |
19108 KB |
n = 2, 122 is a correct answer |
23 |
Correct |
12 ms |
19104 KB |
n = 10, 117 is a correct answer |
24 |
Incorrect |
11 ms |
19020 KB |
n = 10, incorrect answer: jury 336 vs contestant 364 |
25 |
Halted |
0 ms |
0 KB |
- |