#include <bits/stdc++.h>
#include "shortcut.h"
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back
using namespace std;
const int maxN = 510;
typedef long long ll;
typedef long double ld;
const ll oo = 1e18;
ll dp[maxN][maxN], pf[maxN], sf[maxN], ps[maxN];
ll h1[maxN][maxN], h2[maxN][maxN];
ll f[maxN], g[maxN];
long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c)
{
if(n >= maxN) cout << 1/0;
for (int i=1; i<n; i++) ps[i] = ps[i - 1] + l[i - 1];
for (int i=0; i<n; i++)
{
if(i) pf[i] = pf[i - 1] + l[i - 1];
pf[i] = max(pf[i], (ll)d[i]);
}
for (int i=n-1; i>=0; i--)
{
if(i < n - 1) sf[i] = sf[i + 1] + l[i];
sf[i] = max(sf[i], (ll)d[i]);
}
/*
for (int len=1; len<=n; len++)
for (int i=0; i+len<=n; i++)
{
int j = i + len - 1;
if(len == 1) h1[i][i] = (ll)d[i] + ps[i], h2[i][i] = (ll)d[i] - ps[i];
else
{
h1[i][j] = max(h1[i][j - 1], h1[i + 1][j]);
h2[i][j] = max(h2[i][j - 1], h2[i + 1][j]);
}
}
*/
for (int i=0; i<n; i++)
{
if(i) f[i] = f[i - 1];
if(i)f[i] = max(f[i], d[i] + l[i - 1] + pf[i - 1]);
}
for (int i=n-1; i>=0; i--)
{
if(i + 1 < n) g[i] = g[i + 1];
if(i + 1 < n) g[i] = max(g[i], d[i] + l[i] + sf[i + 1]);
}
ll ans = 1e18;
for (int i=0; i<n; i++) ans = max(ans, (ll)d[i]);
for (int i=0; i<n; i++)
for (int j=i+1; j<n; j++)
{
dp[i][j] = pf[i] + sf[j] + min((ll)c, ps[j] - ps[i]);
dp[i][j] = max(dp[i][j], max(f[i], g[j]));
ll len = ps[j] - ps[i] + c;
for (int k=i; k<=j; k++)
{
ll lf = min(ps[k] - ps[i], len - ps[k] + ps[i]);
dp[i][j] = max(dp[i][j], d[k] + lf + pf[i]);
ll rg = min(ps[j] - ps[k], len - ps[j] + ps[k]);
dp[i][j] = max(dp[i][j], d[k] + rg + sf[j]);
}
for (int k=i; k<=j; k++)
for (int e=k+1; e<=j; e++)
dp[i][j] = max(dp[i][j], d[k] + d[e] + min(ps[e] - ps[k], len - ps[e] + ps[k]));
ans = min(ans, dp[i][j]);
}
return ans;
}
Compilation message
shortcut.cpp: In function 'long long int find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:26:25: warning: division by zero [-Wdiv-by-zero]
if(n >= maxN) cout << 1/0;
~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
568 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
3 ms |
568 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
568 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
3 ms |
568 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
568 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
3 ms |
568 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
568 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
3 ms |
568 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
568 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
3 ms |
568 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
568 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
3 ms |
568 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
568 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
3 ms |
568 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
568 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
3 ms |
568 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
568 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
3 ms |
568 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
568 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
3 ms |
568 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
568 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
3 ms |
568 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
568 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
3 ms |
568 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
568 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
3 ms |
568 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
568 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
3 ms |
568 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
3 ms |
568 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
3 ms |
568 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
568 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
3 ms |
568 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |