Submission #1061777

#TimeUsernameProblemLanguageResultExecution timeMemory
1061777RecursiveCoSky Walking (IOI19_walk)C++17
33 / 100
206 ms25788 KiB
#include <bits/stdc++.h> #include "walk.h" using namespace std; long long min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int g) { // Assume s = 0, g = n - 1 and h consists of equal elements. int n = x.size(); // = h.size() int m = l.size(); // = r.size() = y.size() long long ans = x[n - 1] - x[0]; map<pair<int, int>, long long> dp; vector<array<int, 4>> events; for (int i = 0; i < m; i++) { events.push_back({r[i] - 1, y[i], i, 1}); events.push_back({l[i] - 1, y[i], i, 0}); } sort(events.rbegin(), events.rend()); vector<vector<int>> right(n); for (int i = 0; i < m; i++) right[r[i]].push_back(i); set<pair<int, int>> open; int ptr = 0; for (int i = n - 1; i >= 0; i--) { while (ptr < 2 * m && events[ptr][0] >= i) { int yc = events[ptr][1]; int ind = events[ptr][2]; int typ = events[ptr][3]; if (typ) { open.insert({yc, ind}); } else { open.erase({yc, ind}); } ptr++; } for (int ind: right[i]) { long long val = 1e18; auto it = open.lower_bound({y[ind], -1}); if (it != open.end()) { val = min(val, (long long) ((*it).first - y[ind]) + dp[{r[(*it).second], (*it).first}]); } if (it != open.begin()) { it--; val = min(val, (long long) (y[ind] - (*it).first) + dp[{r[(*it).second], (*it).first}]); } dp[{i, y[ind]}] = i == n - 1? y[ind]: val; } } long long extra = 1e18; for (int i = 0; i < m; i++) { if (l[i] == 0) { extra = min(extra, y[i] + dp[{r[i], y[i]}]); } } ans += extra; if (ans >= 1e18) return -1; 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...