답안 #155965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155965 2019-10-02T10:37:12 Z Minnakhmetov 오벨리스크 (NOI14_obelisk) C++14
5 / 25
59 ms 20984 KB
#include <bits/stdc++.h>
   
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
 
using namespace std;
 
struct E {
    int to, w;
};
 
const int N = 11, M = 1e5, INF = 1e9;
vector<pair<int, int>> v[M];
vector<E> g[M];
int s[M];
ll d[M];
 
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    int m, k, sx, sy, ex, ey;
    cin >> k >> m >> sx >> sy >> ex >> ey;
 
    v[k].push_back({sx, sy});
    v[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;
            v[i].push_back({x, y});
        }
    }
 
    for (int i = 0; i < k; i++) {
        s[i + 1] = s[i] + v[i].size();
    }
 
    for (int i = k; i > 0; i--) {
        for (int x = 0; x < v[i].size(); x++) {
            for (int y = 0; y < v[i - 1].size(); y++) {
                int d = abs(v[i][x].first - v[i - 1][y].first) +
                        abs(v[i][x].second - v[i - 1][y].second);
                g[x + s[i]].push_back({y + s[i - 1], d});
            }
        }
    }
 
    // for (int i = 0; i < M; i++) {
    //     for (E e : g[i]) {
    //         cout << i + 1 << " " << e.to + 1 << " " << e.w << "\n";
    //     }
    // }
 
    priority_queue<pair<int, int>, 
                   vector<pair<int, int>>, 
                   greater<pair<int, int>>> q;
                   
    fill(d, d + M, INF);
    d[s[k]] = 0;
    q.push({0, s[k]});
 
    while (!q.empty()) {
        auto p = q.top();
        q.pop();
        if (p.first > d[p.second])
            continue;
        int node = p.second;
 
        for (E e : g[node]) {
            if (d[e.to] > d[node] + e.w) {
                d[e.to] = d[node] + e.w;
                q.push({d[e.to], e.to});
            }
        }
    }
 
    cout << d[0] << "\n";
 
    return 0;
}

Compilation message

obelisk.cpp: In function 'int main()':
obelisk.cpp:44:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int x = 0; x < v[i].size(); x++) {
                         ~~^~~~~~~~~~~~~
obelisk.cpp:45:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int y = 0; y < v[i - 1].size(); y++) {
                             ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5756 KB Output is correct
2 Correct 7 ms 5752 KB Output is correct
3 Correct 7 ms 5752 KB Output is correct
4 Correct 7 ms 5756 KB Output is correct
5 Correct 7 ms 5752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 6008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 19756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 20984 KB Output isn't correct
2 Halted 0 ms 0 KB -