Submission #156003

# Submission time Handle Problem Language Result Execution time Memory
156003 2019-10-02T14:43:38 Z Minnakhmetov OBELISK (NOI14_obelisk) C++14
0 / 25
580 ms 33528 KB
#include <bits/stdc++.h>
   
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
 
using namespace std;
 
struct E {
    int to;
    ll w;
};
 
const ll INF = 1e18;
const int K = 505, H = 105, N = K * H;
vector<pair<int, int>> holes[K];
vector<E> g2[N];
int s[K], dx[3] = {-1, 1, 0};
ll d2[N];
int m, k, sx, sy, ex, ey;

ll calc(int x, int y) {
    ll ans = INF;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            ll p = abs(x + dx[i] * (m + 1)),
                q = abs(y + dx[j] * (m + 1)),
                t1 = x / (m + 1) + (p < 2),
                t2 = y / (m + 1) + (q < 2),
                cur = t1 * 2 + t2 * 2;

            p %= (m + 1);
            q %= (m + 1);

            if (q) {
                if (!t1) {
                    cur += q + 2;
                }
                else {
                    cur += q;
                }
            }


            if (p) {
                if (!t2) {
                    cur += p + 2;
                }
                else {
                    cur += p;
                }
            }

            ans = min(ans, cur);
        }
    }

    return ans;
}
 
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> k >> m >> sx >> sy >> ex >> ey;

    // for (int x = 0; x < C; x++) {
    //     for (int y = 0; y < C; y++) {
    //         if (m == 1) {
    //             addEdge(getId(x, y, 0), getId(x, y, 1), 0);
    //             addEdge(getId(x, y, 1), getId(x, y, 2), 0);
    //         }
    //         if (x + 1 < C) {
    //             addEdge(getId(x, y, 0), getId(x + 1, y, 1), 1);
    //             addEdge(getId(x, y, 2), getId(x + 1, y, 2), 1);
    //         }
    //         if (y + 1 < C) {
    //             addEdge(getId(x, y, 0), getId(x, y + 1, 2), 1);
    //             addEdge(getId(x, y, 1), getId(x, y + 1, 1), 1);
    //         }
    //         if (x + m < C) {
    //             addEdge(getId(x, y, 1), getId(x + m, y, 0), 1);
    //         }
    //         if (y + m < C) {
    //             addEdge(getId(x, y, 2), getId(x, y + m, 0), 1);
    //         }
    //     }
    // }


    // fill(d, d + M, -1);
    // fill(anc, anc + M, -1);
    // int start = getId(Z, Z, 0);
    // d[start] = 0;
    // deque<int> q;
    // q.push_back(start);

    // while (!q.empty()) {
    //     int node = q.front();
    //     q.pop_front();

    //     for (E e : g[node]) {
    //         if (d[e.to] == -1) {
    //             d[e.to] = d[node] + e.w;
    //             anc[e.to] = node;
    //             if (e.w)
    //                 q.push_back(e.to);
    //             else
    //                 q.push_front(e.to);
    //         }
    //     }
    // }

    // for (int i = 0; i <= 5; i++) {
    //     for (int j = 0; j <= 5; j++) {
    //         int cur = d[getId(Z + i, Z + j, 0)] ;
    //         if (cur < 10)
    //             cout << " ";
    //         cout << d[getId(Z + i, Z + j, 0)] << "/";


    //         int cur2 = calc(i, j);
            

    //         if (cur2 < 10)
    //             cout << " ";
    //         cout << cur2 << " ";
    //     }
    //     cout << "\n";
    // }

    // pr(getId(2 + Z, 2 + Z, 0));

    // return 0;
    // cout << d[getId(Z + 1, Z + 1, 0)];
    // return 0;


    holes[k].push_back({sx, sy});
    holes[0].push_back({ex, ey});

    for (int i = k - 1; i > 0; i--) {
        int h;
        cin >> h;

        while (h--) {
            int x, y;
            cin >> x >> y;
            holes[i].push_back({x, y});
        }
    }


    for (int i = 0; i < k; i++) {
        s[i + 1] = s[i] + holes[i].size();
    }

    for (int i = 1; i <= k; i++) {
        for (int x = 0; x < holes[i].size(); x++) {
            for (int y = 0; y < holes[i - 1].size(); y++) {
                ll dist = calc(holes[i - 1][y].first - holes[i][x].first,
                                holes[i - 1][y].second - holes[i][x].second);
                g2[x + s[i]].push_back({y + s[i - 1], dist});
            }
        }
    }

    priority_queue<pair<ll, int>, 
               vector<pair<ll, int>>, 
               greater<pair<ll, int>>> pq;
                   
    fill(d2, d2 + N, INF);
    d2[s[k]] = 0;
    pq.push({0ll, s[k]});
 
    while (!pq.empty()) {
        auto p = pq.top();
        pq.pop();
        if (p.first > d2[p.second])
            continue;
        int node = p.second;
 
        for (E e : g2[node]) {
            if (d2[e.to] > d2[node] + e.w) {
                d2[e.to] = d2[node] + e.w;
                pq.push({d2[e.to], e.to});
            }
        }
    }
 
    cout << d2[0] << "\n";

    return 0;
}

Compilation message

obelisk.cpp: In function 'int main()':
obelisk.cpp:158:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int x = 0; x < holes[i].size(); x++) {
                         ~~^~~~~~~~~~~~~~~~~
obelisk.cpp:159:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int y = 0; y < holes[i - 1].size(); y++) {
                             ~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 2296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 363 ms 29672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 580 ms 33528 KB Output isn't correct
2 Halted 0 ms 0 KB -