Submission #44193

#TimeUsernameProblemLanguageResultExecution timeMemory
44193wasylOBELISK (NOI14_obelisk)C++11
25 / 25
50 ms2436 KiB
#include <bits/stdc++.h> #ifndef dbg #define dbg(...) #endif #define all(x) begin(x), end(x) #define rsz(...) resize(__VA_ARGS__) #define psh(...) push_back(__VA_ARGS__) #define emp(...) emplace_back(__VA_ARGS__) #define prt(...) print(cout, __VA_ARGS__) #define dmp(...) print(cerr, #__VA_ARGS__, '=', __VA_ARGS__) #define dprt(...) dbg(print(cerr,__VA_ARGS__)) #define ddmp(...) dbg(dmp(__VA_ARGS__)) using namespace std;using ll=long long; template<typename t>using V=vector<t>; template<typename t>void print(ostream& os, const t& a){os<<a<<'\n';} template<typename t, typename... A>void print (ostream& os, const t& a, A&&... b){os<<a<<' ';print(os, b...);} constexpr ll INF = 1e15 + 1; struct Point { int x, y; Point(int x, int y): x(x), y(y){} }; struct State { Point v; ll val; State(Point v, ll val = 0): v(v), val(val){} State(int x, int y, ll val = 0): v(x, y), val(val){} }; int k, m, v; V< V< State > > dp; inline Point turn_to_vector(const Point& a, const Point& b) { return Point(abs(a.x - b.x), abs(a.y - b.y)); } inline ll cost (int a, bool p, bool q) { if (a == 0) return (p? 2 : 0); if (not p) return a; if (not q and a % v == 0) return a / v * 2; if (not q and a % v != 0) return INF; return min( max(2LL, (ll)(a / v) * 2) + a - ((a / v) * v), (ll)(a / v) * 2 + 2 + (((a / v) * v + v) - a)); } inline ll cost(const Point& a) { if (a.x == 0 and a.y == 0) return 0; if (m == 1) return a.x + a.y; return min({ cost(a.x, 0, 1) + cost(a.y, 1 ,0), cost(a.x, 1, 0) + cost(a.y, 0, 1), cost(a.x, 1, 1) + cost(a.y, 1, 1)}); } inline void proceed() { for (auto& q : dp[1]) { ll cos = LLONG_MAX; ddmp(q.v.x, q.v.y, q.val); for (auto& p : dp[0]) { cos = min(cos, p.val + cost(turn_to_vector(p.v, q.v))); ddmp(p.v.x, p.v.y, p.val); } q.val += cos; ddmp(q.val); } swap(dp[0], dp[1]); dp[1].clear(); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> k >> m; v = m + 1; int stx, sty, enx, eny; cin >> stx >> sty >> enx >> eny; dp.rsz(2); dp[0].emp(stx, sty); for (int i = 0; i < k - 1; ++i) { int h; cin >> h; for (int i = 0; i < h; ++i) { int x, y; cin >> x >> y; dp[1].emp(x, y); } proceed(); } dp[1].emp(enx, eny); proceed(); prt(dp[0][0].val); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...