#include "shortcut.h"
#ifndef EVAL
#include "grader.cpp"
#endif // EVAL
#include <bits/stdc++.h>
using namespace std;
#define lol long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scanl(a) scanf("%lld",&a);
#define scanll(a,b) scanf("%lld %lld",&a, &b);
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-12
const int INF = 1e17;
int dia,iz,dis[1000001];
vector <pii> g[1000001];
lol find_shortcut(int n, vector<int> l, vector<int> d, int c){
int i,j,mx=0,x=0,y=0,pos=0,ans=0;
vector <pair<lol,pii> > v;
for (i=0;i<n;++i){
mx = d[i];
for (j=i+1;j<n;++j){
mx += l[j-1];
if (mx+d[j] > ans){
ans = mx+d[j];
x = i;
y = j;
}
}
}
for (i=0;i<n;++i){
if (d[i] > 0){
g[i].pb({i+n,d[i]});
g[i+n].pb({i,d[i]});
}
if (i+1 < n){
g[i].pb({i+1,l[i]});
g[i+1].pb({i,l[i]});
}
}
g[x].pb({y,c});
g[y].pb({x,c});
{
set <pii> s;
int start = 0;
for (i=0;i<n*2;++i)dis[i] = INF;
s.insert({0,start});
dis[start] = 0;
while (!s.empty()){
int x = s.begin()->sc,cost = s.begin()->fr;
s.erase(s.begin());
for (pii to: g[x]){
if (to.sc+cost < dis[to.fr]){
s.erase({dis[to.fr],to.fr});
dis[to.fr] = to.sc+cost;
s.insert({dis[to.fr],to.fr});
}
}
}
ans =0 ;
for (i=0;i<n*2;++i){
if (dis[i] > ans && dis[i] != INF){
ans = dis[i];
iz = i;
}
dis[i] = INF;
}
}
{
set <pii> s;
int start = iz;
for (i=0;i<n*2;++i)dis[i] = INF;
s.insert({0,start});
dis[start] = 0;
while (!s.empty()){
int x = s.begin()->sc,cost = s.begin()->fr;
s.erase(s.begin());
for (pii to: g[x]){
if (to.sc+cost < dis[to.fr]){
s.erase({dis[to.fr],to.fr});
dis[to.fr] = to.sc+cost;
s.insert({dis[to.fr],to.fr});
}
}
}
ans =0 ;
for (i=0;i<n*2;++i){
if (dis[i] > ans && dis[i] != INF){
ans = dis[i];
}
}
}
ret ans;
}
Compilation message
shortcut.cpp:27:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+17' to '2147483647' [-Woverflow]
27 | const int INF = 1e17;
| ^~~~
shortcut.cpp: In function 'long long int find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:32:26: warning: unused variable 'pos' [-Wunused-variable]
32 | int i,j,mx=0,x=0,y=0,pos=0,ans=0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
16 ms |
23788 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
19 ms |
23788 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
16 ms |
23788 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
16 ms |
23788 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
17 ms |
23808 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
16 ms |
23872 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
17 ms |
23932 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
17 ms |
23788 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
17 ms |
23788 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 0 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
16 ms |
23788 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
19 ms |
23788 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
16 ms |
23788 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
16 ms |
23788 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
17 ms |
23808 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
16 ms |
23872 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
17 ms |
23932 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
17 ms |
23788 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
17 ms |
23788 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 0 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
16 ms |
23788 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
19 ms |
23788 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
16 ms |
23788 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
16 ms |
23788 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
17 ms |
23808 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
16 ms |
23872 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
17 ms |
23932 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
17 ms |
23788 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
17 ms |
23788 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 0 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
16 ms |
23788 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
19 ms |
23788 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
16 ms |
23788 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
16 ms |
23788 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
17 ms |
23808 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
16 ms |
23872 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
17 ms |
23932 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
17 ms |
23788 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
17 ms |
23788 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 0 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
16 ms |
23788 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
19 ms |
23788 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
16 ms |
23788 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
16 ms |
23788 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
17 ms |
23808 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
16 ms |
23872 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
17 ms |
23932 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
17 ms |
23788 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
17 ms |
23788 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 0 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
16 ms |
23788 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
19 ms |
23788 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
16 ms |
23788 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
16 ms |
23788 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
17 ms |
23808 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
16 ms |
23872 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
17 ms |
23932 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
17 ms |
23788 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
17 ms |
23788 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 0 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
16 ms |
23788 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
19 ms |
23788 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
16 ms |
23788 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
16 ms |
23788 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
17 ms |
23808 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
16 ms |
23872 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
17 ms |
23932 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
17 ms |
23788 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
17 ms |
23788 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 0 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
16 ms |
23788 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
19 ms |
23788 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
16 ms |
23788 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
16 ms |
23788 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
17 ms |
23808 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
16 ms |
23872 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
17 ms |
23932 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
17 ms |
23788 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
17 ms |
23788 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 0 |
11 |
Halted |
0 ms |
0 KB |
- |