Submission #44189

# Submission time Handle Problem Language Result Execution time Memory
44189 2018-03-30T10:36:29 Z wasyl OBELISK (NOI14_obelisk) C++11
0 / 25
43 ms 2496 KB
#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(
        (a / v) * 2 + a - ((a / v) * v),
        (a / v) * 2 + 2 + (((a / v) * v + v) - a));    
}

inline ll cost(const Point& a)
{
    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 time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 1300 KB Output is correct
2 Correct 34 ms 1832 KB Output is correct
3 Incorrect 35 ms 2496 KB Output isn't correct
4 Halted 0 ms 0 KB -