# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
416549 | 2021-06-02T15:16:09 Z | idk321 | Sky Walking (IOI19_walk) | C++17 | 74 ms | 54712 KB |
#include "walk.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int M = 2000005; const int N = 100005; const ll INF = 2000000000000000000LL; vector<int> adj[M]; vector<array<int, 2>> isAt[N]; int cnode = 0; ll dp[N]; ///usr/include/c++/10/bits/stl_heap.h|209|error: ‘bool Comparator::operator()(const std::__debug::array<long long int, 2>&, const std::__debug::array<long long int, 2>&) const’ is private within this context| struct Comparator { bool operator() (const array<ll, 2>& ar1, const array<ll, 2>& ar2) const { return tie(ar1[1], ar1[0]) < tie(ar2[1], ar2[0]); } }; long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int s, int g) { vector<vector<int>> startsAt(x.size()); vector<vector<int>> endsAt(x.size()); for (int i = 0; i < l.size(); i++) { startsAt[l[i]].push_back(i); endsAt[r[i]].push_back(i); } multiset<array<int, 2>> sett; vector<int> in(y.size()); for (int i = 0; i < x.size(); i++) { for (int j : endsAt[i]) { sett.erase(sett.find({y[j], j})); } for (int j : startsAt[i]) { sett.insert({y[j], j}); } for (int j : endsAt[i]) { auto it = sett.upper_bound({y[j], -1}); if (it != sett.end()) { adj[(*it)[1]].push_back(j); in[j]++; } if (it != sett.begin()) { it--; adj[(*it)[1]].push_back(j); in[j]++; } } } for (int i = 0; i <N; i++) dp[i] = INF; for (int i : endsAt[x.size() - 1]) { dp[i] = y[i]; } vector<int> noIn; for (int i = 0; i < in.size(); i++) { if (in[i] == 0) { noIn.push_back(i); } } while (!noIn.empty()) { int cur = noIn.back(); noIn.pop_back(); for (int next : adj[cur]) { in[next]--; dp[next] = min(dp[cur] + abs(y[cur] - y[next]), dp[next]); if (in[next] == 0) noIn.push_back(next); } } int small = 2000000000; int ismall = -1; for (int i : startsAt[0]) { if (y[i] < small) { small = y[i]; ismall = i; } } if (dp[ismall] == INF) return -1; return dp[ismall] + x.back() - x.front(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 50292 KB | Output is correct |
2 | Incorrect | 35 ms | 50372 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 35 ms | 50312 KB | Output is correct |
2 | Incorrect | 32 ms | 50380 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 74 ms | 54712 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 74 ms | 54712 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 50292 KB | Output is correct |
2 | Incorrect | 35 ms | 50372 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |