Submission #1042814

#TimeUsernameProblemLanguageResultExecution timeMemory
1042814ZicrusShortcut (IOI16_shortcut)C++17
0 / 100
1 ms600 KiB
#include <bits/stdc++.h> #include "shortcut.h" using namespace std; typedef long long ll; ll find_shortcut(int n, vector<int> l, vector<int> s, int c) { vector<ll> dist(n), preMax(n), postMax(n); preMax[0] = s[0]; for (int i = 1; i < n; i++) { dist[i] = dist[i-1] + l[i-1]; preMax[i] = max(preMax[i-1] + l[i-1], (ll)s[i]); } postMax[n-1] = s[n-1]; for (int i = n-2; i >= 0; i--) { postMax[i] = max(postMax[i+1] + l[i], (ll)s[i]); } ll res = 1ll << 62ll; for (int low = 0; low < n-1; low++) { for (int high = low+1; high < n; high++) { if (c >= dist[high] - dist[low]) continue; // Left to right ll dia = c + preMax[low] + postMax[high]; // Left to mid ll id = low+1; // First id where it's better to take the highway while (id < high) { if (dist[id] - dist[low] >= c + dist[high] - dist[id]) break; // Normal route dia = max(dia, preMax[low] + dist[id] - dist[low] + s[id]); id++; } for (int i = id; i < high; i++) { dia = max(dia, preMax[low] + c + dist[high] - dist[i] + s[i]); } // Right to mid id = high-1; // First id where it's better to take the highway while (id > low) { if (dist[high] - dist[id] >= c + dist[id] - dist[low]) break; // Normal route dia = max(dia, postMax[high] + dist[high] - dist[id] + s[id]); id--; } for (int i = id; i > low; i--) { dia = max(dia, postMax[high] + c + dist[i] - dist[low] + s[i]); } // Mid for (int i = low; i < high; i++) { for (int j = i+1; j <= high; j++) { ll dst = min(dist[j] - dist[i], abs(dist[i] - dist[low]) + c + abs(dist[high] - dist[j])) + s[i] + s[j]; dia = max(dia, dst); } } for (int i = 0; i < low; i++) { for (int j = i+1; j <= low; j++) { ll dst = min(dist[j] - dist[i], abs(dist[i] - dist[0]) + c + abs(dist[low] - dist[j])) + s[i] + s[j]; dia = max(dia, dst); } } for (int i = high; i < n-1; i++) { for (int j = i+1; j <= n-1; j++) { ll dst = min(dist[j] - dist[i], abs(dist[i] - dist[high]) + c + abs(dist[n-1] - dist[j])) + s[i] + s[j]; dia = max(dia, dst); } } res = min(res, dia); } } if (res > 1ll << 61ll) { res = 0; for (int i = 0; i < n-1; i++) { for (int j = i+1; j <= n-1; j++) { ll dst = min(dist[j] - dist[i], abs(dist[i] - dist[0]) + c + abs(dist[n-1] - dist[j])) + s[i] + s[j]; res = max(res, dst); } } } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...