Submission #778780

#TimeUsernameProblemLanguageResultExecution timeMemory
778780vjudge1Shortcut (IOI16_shortcut)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; #include "shortcut.h" #define sp " " #define endl "\n" #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define fastio() cin.tie(0), ios_base::sync_with_stdio(0) #define pb push_back #define pii pair<int, int> #define st first #define nd second #define ll long long const ll INF = 2e18 + 7; long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c) { vector<ll> pre(n + 5, 0), suf(n + 5, 0), dist(n + 5, 0); ll maks[n + 5][n + 5], maks2[n + 5][n + 5]; for (int i = 0; i < n + 5; i++){ for (int j = 0; j < n + 5; j++) maks[i][j] = 0, maks2[i][j] = 0; } pre[0] = d[0]; for (int i = 1; i < n; i++){ pre[i] = pre[i - 1] + l[i - 1]; pre[i] = max(pre[i], (ll)d[i]); } suf[n - 1] = d[n - 1]; for (int i = n - 2; i >= 0; i--){ suf[i] = suf[i + 1] + l[i]; suf[i] = max(suf[i], (ll)d[i]); } for (int i = 1; i < n; i++) dist[i] = dist[i - 1] + l[i - 1]; for (int i = 0; i < n; i++){ maks[i][i] = d[i]; for (int j = i -1; j >= 0; j--){ maks[j][i] = max(maks[j + 1][i], dist[i] - dist[j] + d[j]); } } for (int i = 0; i < n; i++){ maks2[i][i] = d[i]; for (int j = i + 1; j < n; j++){ maks2[i][j] = max(maks2[i][j - 1], dist[j] - dist[i] + d[j] + d[i]); } } ll ans = 0; for (int i = 0; i < n; i++){ ans = max(ans, (ll)d[i]); for (int j = i + 1; j < n; j++){ ans = max(ans, dist[j] - dist[i] + d[i] + d[j]); } } for (int i = 0; i < n; i++){ for (int j = i; j < n; j++){ if (dist[j] - dist[i] <= c) continue; ll pos = i, curr = pre[i] + suf[j] + c; for (int k = i; k <= j; k++){ curr = max(curr, suf[j] + d[k] + min(dist[k] - dist[i] + c, dist[j] - dist[k])); curr = max(curr, pre[i] + d[k] + min(dist[k] - dist[i], dist[j] - dist[k] + c)); while(pos <= j && dist[pos] - dist[k] < dist[j] - dist[pos] + dist[k] - dist[i] + c){ pos++; } if (pos <= j) curr = max(curr, d[k] + dist[k] - dist[i] + c + maks[pos][j]); if (pos > k) curr = max(curr, maks2[k][pos - 1]); curr = max(curr, (ll)d[k]); pos = max(pos, (ll)k + 2); } //cout<<i<<sp<<j<<sp<<curr<<endl; ans = min(ans, curr); } } return ans; }
#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...