#include "shortcut.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAXN=5100;
const ll INF=1e9+10;
#define dbg(x) cout<<" [ "<<#x<<" ] : "<<x<<endl;
#define F first
#define S second
#define all(v) v.begin(),v.end()
long long find_shortcut(int n, vector<int> l, vector<int> d, int c)
{
if(n==2){
if(c<l[0])
return d[0]+c+d[1];
return d[0]+l[0]+d[1];
}
vector<int> pref(MAXN+1,0);
for(int i=0;i<n-1;i++){
pref[i+1]=pref[i]+l[i];
}
vector<int> left(MAXN+1,0);
vector<int> right(MAXN+1,0);
//the idea is to use pref[i-1]+l[i] or d[i]
left[0]=d[0];
int first_node=0;
for(int i=1;i<n;i++){
if(d[i]>left[i-1]+l[i-1]) first_node=i;
left[i]=max(left[i-1]+l[i-1],d[i]);
}
int last_node=n-1;
right[n-1]=d[n-1];
for(int i=n-2;i>=0;i--){
if(d[i]>right[i+1]+l[i]) last_node=i;
right[i]=max(right[i+1]+l[i],d[i]);
}
vector<int> nodes;//nodes in the diameter
// cout<<first_node<<" "<<last_node<<endl;
int diameter=left[first_node]+right[first_node];
// cout<<diameter<<endl;
for(int i=first_node;i<=last_node;i++){
for(int j=i+1;j<=last_node;j++){
int express=left[i]+c+right[j];
int newdiameter=0;
for(int k=0;k<=n-1;k++){
newdiameter=max(newdiameter,abs(pref[j]-pref[k])+right[j]);
}
for(int k=n-1;k>=0;k--){
newdiameter=max(newdiameter,abs(pref[k]-pref[i])+left[i]);
}
// if(i==0&&j==7){
// cout<<pref[j]-
// }
// cout<<newdiameter<<" "<<express<<" "<<i<<" "<<j<<endl;
// if(newdiameter>express) continue;
diameter=min({max(newdiameter,express),diameter});
}
}
// cout<<c<<endl;
return diameter;
}
// int main()
// {
// int n, c;
// assert(2 == scanf("%d%d", &n, &c));
// std::vector<int> l(n - 1);
// std::vector<int> d(n);
// for (int i = 0; i < n - 1; i++)
// assert(1 == scanf("%d", &l[i]));
// for (int i = 0; i < n; i++)
// assert(1 == scanf("%d", &d[i]));
// long long t = find_shortcut(n, l, d, c);
// printf("%lld\n", t);
// return 0;
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
340 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
340 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
340 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
1 ms |
340 KB |
n = 3, incorrect answer: jury 29 vs contestant 38 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
340 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
340 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
340 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
1 ms |
340 KB |
n = 3, incorrect answer: jury 29 vs contestant 38 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
340 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
340 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
340 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
1 ms |
340 KB |
n = 3, incorrect answer: jury 29 vs contestant 38 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
340 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
340 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
340 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
1 ms |
340 KB |
n = 3, incorrect answer: jury 29 vs contestant 38 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
340 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
340 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
340 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
1 ms |
340 KB |
n = 3, incorrect answer: jury 29 vs contestant 38 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
340 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
340 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
340 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
1 ms |
340 KB |
n = 3, incorrect answer: jury 29 vs contestant 38 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
340 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
340 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
340 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
1 ms |
340 KB |
n = 3, incorrect answer: jury 29 vs contestant 38 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
340 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
340 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
340 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
1 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Incorrect |
1 ms |
340 KB |
n = 3, incorrect answer: jury 29 vs contestant 38 |
8 |
Halted |
0 ms |
0 KB |
- |