답안 #155970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155970 2019-10-02T11:08:06 Z Minnakhmetov 오벨리스크 (NOI14_obelisk) C++14
0 / 25
138 ms 48052 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 K = 11, M = 1e6, C = 105, Z = 52, INF = 1e9;
vector<E> g[M];
int d[M];
bool hole[K][C][C];

int getId(int x, int y, int z, int k) {
    return k * C * C * 3 + x * C * 3 + y * 3 + z;
}

void addEdge(int a, int b, int c) {
    g[a].push_back({b, c});
    g[b].push_back({a, c});
}
 
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;

    sx += Z;
    sy += Z;
    ex += Z;
    ey += Z;
 
    for (int i = k - 1; i > 0; i--) {
        int h;
        cin >> h;
 
        while (h--) {
            int x, y;
            cin >> x >> y;
            x += Z;
            y += Z;
            hole[i][x][y] = 1;
            g[getId(x, y, 0, i)].push_back({getId(x, y, 0, i - 1), 0});
        }
    }

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

    fill(d, d + M, -1);
    int start = getId(sx, sy, 0, k - 1);
    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;
                if (e.w)
                    q.push_back(e.to);
                else
                    q.push_front(e.to);
            }
        }
    }

    cout << d[getId(ex, ey, 0, 0)];

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 124 ms 43512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 43456 KB Output is correct
2 Correct 138 ms 43520 KB Output is correct
3 Correct 118 ms 43256 KB Output is correct
4 Correct 117 ms 43476 KB Output is correct
5 Incorrect 119 ms 43384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 53 ms 48052 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 58 ms 48040 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -