#include "shortcut.h"
#include <bits/stdc++.h>
#define N 200005
using namespace std;
vector<pair<int,int>> adj[N];
bool on_circle[N];
long long ret = 0;
long long dfs(int v,int par){
long long maxi = 0;
for(auto u:adj[v]){
if(u.first == par || on_circle[u.first])continue;
long long tmp = dfs(u.first,v) + u.second;
ret = max(ret,maxi + tmp);
maxi = max(maxi,tmp);
}
return maxi;
}
long long get_ans(vector<int> circle,vector<int> circle_edges){
assert(circle.size() == circle_edges.size());
for(auto u:circle){
on_circle[u] = 1;
}
ret = 0;
vector<long long> depths;
for(auto u:circle){
depths.push_back(dfs(u,-1));
}
long long circle_length = 0;
for(auto u:circle_edges){
circle_length += u;
}
vector<long long> d = {0};
for(int i = 1;i<circle.size();i++){
d.push_back(d[i-1] + circle_edges[i-1]);
}
multiset<int> s1;
multiset<int> s2;
for(int i = 0;i<circle.size();i++){
s2.insert(depths[i] - d[i] + circle_length);
}
int pt1 = -1;
for(int i = 0;i<circle.size();i++){
while(pt1 + 1 < circle.size() && (d[pt1+1] - d[i]) < circle_length - (d[pt1 + 1] - d[i])){
pt1++;
s1.insert(d[pt1] + depths[pt1]);
s2.erase(s2.find(depths[pt1] - d[pt1] + circle_length));
}
s1.erase(s1.find(d[i] + depths[i]));
if(s1.size()){
ret = max(ret,*s1.rbegin()+depths[i] -d[i]);
}
if(s2.size()){
ret = max(ret,*s2.rbegin()+depths[i] +d[i]);
}
/*
for(int j = i+1;j<circle.size();j++){
ret = max(ret,min(d[j]-d[i],circle_length - (d[j] - d[i])) + depths[i] + depths[j]);
}*/
}
for(auto u:circle){
on_circle[u] = 0;
}
return ret;
}
long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int nwedge)
{
for(int i = 0;i<n-1;i++){
adj[i].push_back({i+1,l[i]});
adj[i+1].push_back({i,l[i]});
}
for(int i = 0;i<n;i++){
adj[i].push_back({i+n,d[i]});
adj[i+n].push_back({i,d[i]});
}
long long ans = 1e18;
for(int i = 0;i<n;i++){
vector<int> circle;
vector<int> circle_edges;
for(int j = i;j<n;j++){
{
circle.clear();
circle_edges.clear();
for(int c = i;c<=j;c++){
circle.push_back(c);
if(c != i)
circle_edges.push_back(l[c-1]);
}
circle_edges.push_back(nwedge);
adj[i].push_back({j,nwedge});
adj[j].push_back({i,nwedge});
ans = min(ans,get_ans(circle,circle_edges));
adj[i].pop_back();
adj[j].pop_back();
}
}
}
return ans;
}
Compilation message
shortcut.cpp: In function 'long long int get_ans(std::vector<int>, std::vector<int>)':
shortcut.cpp:33:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int i = 1;i<circle.size();i++){
| ~^~~~~~~~~~~~~~
shortcut.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i = 0;i<circle.size();i++){
| ~^~~~~~~~~~~~~~
shortcut.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i = 0;i<circle.size();i++){
| ~^~~~~~~~~~~~~~
shortcut.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | while(pt1 + 1 < circle.size() && (d[pt1+1] - d[i]) < circle_length - (d[pt1 + 1] - d[i])){
| ~~~~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
4932 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
3 ms |
4948 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
3 ms |
4948 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
3 ms |
4948 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
4 ms |
5004 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
3 ms |
4948 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
4948 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
4948 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
3 ms |
4948 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
4 ms |
4940 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
4 ms |
4948 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
3 ms |
4948 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
3 ms |
5000 KB |
n = 4, 3000000001 is a correct answer |
15 |
Incorrect |
3 ms |
4948 KB |
n = 4, incorrect answer: jury 4000000000 vs contestant 3000000000 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
4932 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
3 ms |
4948 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
3 ms |
4948 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
3 ms |
4948 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
4 ms |
5004 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
3 ms |
4948 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
4948 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
4948 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
3 ms |
4948 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
4 ms |
4940 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
4 ms |
4948 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
3 ms |
4948 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
3 ms |
5000 KB |
n = 4, 3000000001 is a correct answer |
15 |
Incorrect |
3 ms |
4948 KB |
n = 4, incorrect answer: jury 4000000000 vs contestant 3000000000 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
4932 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
3 ms |
4948 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
3 ms |
4948 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
3 ms |
4948 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
4 ms |
5004 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
3 ms |
4948 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
4948 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
4948 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
3 ms |
4948 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
4 ms |
4940 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
4 ms |
4948 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
3 ms |
4948 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
3 ms |
5000 KB |
n = 4, 3000000001 is a correct answer |
15 |
Incorrect |
3 ms |
4948 KB |
n = 4, incorrect answer: jury 4000000000 vs contestant 3000000000 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
4932 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
3 ms |
4948 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
3 ms |
4948 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
3 ms |
4948 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
4 ms |
5004 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
3 ms |
4948 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
4948 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
4948 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
3 ms |
4948 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
4 ms |
4940 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
4 ms |
4948 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
3 ms |
4948 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
3 ms |
5000 KB |
n = 4, 3000000001 is a correct answer |
15 |
Incorrect |
3 ms |
4948 KB |
n = 4, incorrect answer: jury 4000000000 vs contestant 3000000000 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
4932 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
3 ms |
4948 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
3 ms |
4948 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
3 ms |
4948 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
4 ms |
5004 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
3 ms |
4948 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
4948 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
4948 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
3 ms |
4948 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
4 ms |
4940 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
4 ms |
4948 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
3 ms |
4948 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
3 ms |
5000 KB |
n = 4, 3000000001 is a correct answer |
15 |
Incorrect |
3 ms |
4948 KB |
n = 4, incorrect answer: jury 4000000000 vs contestant 3000000000 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
4932 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
3 ms |
4948 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
3 ms |
4948 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
3 ms |
4948 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
4 ms |
5004 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
3 ms |
4948 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
4948 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
4948 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
3 ms |
4948 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
4 ms |
4940 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
4 ms |
4948 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
3 ms |
4948 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
3 ms |
5000 KB |
n = 4, 3000000001 is a correct answer |
15 |
Incorrect |
3 ms |
4948 KB |
n = 4, incorrect answer: jury 4000000000 vs contestant 3000000000 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
4932 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
3 ms |
4948 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
3 ms |
4948 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
3 ms |
4948 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
4 ms |
5004 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
3 ms |
4948 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
4948 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
4948 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
3 ms |
4948 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
4 ms |
4940 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
4 ms |
4948 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
3 ms |
4948 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
3 ms |
5000 KB |
n = 4, 3000000001 is a correct answer |
15 |
Incorrect |
3 ms |
4948 KB |
n = 4, incorrect answer: jury 4000000000 vs contestant 3000000000 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
4932 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
3 ms |
4948 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
3 ms |
4948 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
3 ms |
4948 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
4 ms |
5004 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
3 ms |
4948 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
2 ms |
4948 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
2 ms |
4948 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
3 ms |
4948 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
4 ms |
4940 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
4 ms |
4948 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
3 ms |
4948 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
3 ms |
5000 KB |
n = 4, 3000000001 is a correct answer |
15 |
Incorrect |
3 ms |
4948 KB |
n = 4, incorrect answer: jury 4000000000 vs contestant 3000000000 |
16 |
Halted |
0 ms |
0 KB |
- |