Submission #14401

# Submission time Handle Problem Language Result Execution time Memory
14401 2015-05-14T05:40:06 Z gs14004 Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 184044 KB
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;

int m, n;

vector<int> vertex;
vector<int> dummy[30005];
vector<int> dx[30005];

bool r_dir[30005][180], l_dir[30005][180];

vector<vector<int> > graph0;
vector<int> graph1;
vector<bool> vis;

queue<int> pq[2];

inline int oldpi(int i, int j){
    return n * j + i;
}

inline int oldpi_first(int p){
    return (p % n + n) % n;
}

inline int oldpi_second(int p){
    return (p - oldpi_first(p)) / n;
}

int dijkstra(int st, int ed){
    pq[0].push(st);
    int dist = 0;
    while (1) {
        if(pq[dist%2].empty()) break;
        while (!pq[dist%2].empty()) {
            int qf = pq[dist%2].front();
            pq[dist%2].pop();
            if(qf == ed){
                return dist;
            }
            if(vis[qf]) continue;
            vis[qf] = 1;
            for (auto &i : graph0[qf]){
                if(!vis[i]){
                    pq[dist%2].push(i);
                }
            }
            if(graph1[qf] != 0){
                pq[(dist+1)%2].push(graph1[qf]);
            }
        }
        dist++;
    }
    return -1;
}

int main(){
    int st = 0, ed = 0;
    scanf("%d %d",&n,&m);
    for (int i=0; i<m; i++) {
        int x,y;
        scanf("%d %d",&x,&y);
        if(i == 0){
            st = x;
        }
        else if(i == 1){
            ed = x;
        }
        if(y < 180){
            r_dir[x][y] = 1;
            l_dir[x][y] = 1;
        }
        else{
            for (int j=0; j * y + x < n; j++) {
                dx[j * y + x].push_back(y);
            }
            for (int j=0; j * y + x >= 0; j--) {
                dx[j * y + x].push_back(-y);
            }
        }
        dummy[x].push_back(y);
    }
    for (int i=1; i<180; i++) {
        for (int j=i; j<n; j++) {
            r_dir[j][i] |= r_dir[j - i][i];
        }
        for (int j=n-i-1; j>=0; j--) {
            l_dir[j][i] |= l_dir[j + i][i];
        }
        for (int j=0; j<n; j++) {
            if(r_dir[j][i]){
                dx[j].push_back(i);
            }
            if(l_dir[j][i]){
                dx[j].push_back(-i);
            }
        }
    }
    for (int i=0; i<n; i++) {
        sort(dx[i].begin(),dx[i].end());
        dx[i].resize(unique(dx[i].begin(),dx[i].end()) - dx[i].begin());
        for (auto &j : dx[i]){
            vertex.push_back(oldpi(i,j));
        }
    }
    sort(vertex.begin(),vertex.end());
    graph0.resize(n + vertex.size());
    graph1.resize(n + vertex.size());
    vis.resize(n + vertex.size());
    for (int i=0; i<n; i++) {
        for(auto &j : dummy[i]){
            int pos = (int)(lower_bound(vertex.begin(),vertex.end(),oldpi(i,j)) - vertex.begin());
            if(pos != vertex.size() && vertex[pos] == oldpi(i,j)){
                graph0[i].push_back(pos + n);
            }
            pos = (int)(lower_bound(vertex.begin(),vertex.end(),oldpi(i,-j)) - vertex.begin());
            if(pos != vertex.size() && vertex[pos] == oldpi(i,-j)){
                graph0[i].push_back(pos + n);
            }
        }
    }
    for (int i=0; i<vertex.size(); i++){
        int tmp = vertex[i];
        graph0[i+n].push_back(oldpi_first(vertex[i]));
        if(oldpi_first(tmp) + oldpi_second(tmp) < 0 || oldpi_first(tmp) + oldpi_second(tmp) >= n)
            continue;
        
        tmp = oldpi(oldpi_first(tmp) + oldpi_second(tmp),oldpi_second(tmp));
        int np = (int)(lower_bound(vertex.begin(),vertex.end(),tmp) - vertex.begin());
        if(np == vertex.size() || vertex[np] != tmp) continue;
        graph1[i+n] = np + n;
    }
    printf("%d\n",dijkstra(st,ed));
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13544 KB Output is correct
2 Correct 0 ms 13544 KB Output is correct
3 Correct 0 ms 13544 KB Output is correct
4 Correct 0 ms 13544 KB Output is correct
5 Correct 0 ms 13544 KB Output is correct
6 Correct 0 ms 13544 KB Output is correct
7 Correct 0 ms 13544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13544 KB Output is correct
2 Correct 0 ms 13544 KB Output is correct
3 Correct 0 ms 13544 KB Output is correct
4 Correct 1 ms 13544 KB Output is correct
5 Correct 0 ms 13544 KB Output is correct
6 Correct 0 ms 13544 KB Output is correct
7 Correct 0 ms 13544 KB Output is correct
8 Correct 0 ms 13544 KB Output is correct
9 Correct 0 ms 13544 KB Output is correct
10 Correct 0 ms 13676 KB Output is correct
11 Correct 0 ms 13968 KB Output is correct
12 Correct 2 ms 13544 KB Output is correct
13 Correct 0 ms 13544 KB Output is correct
14 Correct 4 ms 14028 KB Output is correct
15 Correct 5 ms 14032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13544 KB Output is correct
2 Correct 0 ms 13544 KB Output is correct
3 Correct 1 ms 13544 KB Output is correct
4 Correct 0 ms 13544 KB Output is correct
5 Correct 0 ms 13544 KB Output is correct
6 Correct 0 ms 13544 KB Output is correct
7 Correct 0 ms 13544 KB Output is correct
8 Correct 0 ms 13544 KB Output is correct
9 Correct 0 ms 13544 KB Output is correct
10 Correct 0 ms 13676 KB Output is correct
11 Correct 0 ms 13968 KB Output is correct
12 Correct 0 ms 13544 KB Output is correct
13 Correct 0 ms 13544 KB Output is correct
14 Correct 4 ms 14028 KB Output is correct
15 Correct 2 ms 14032 KB Output is correct
16 Correct 4 ms 13920 KB Output is correct
17 Correct 6 ms 14828 KB Output is correct
18 Correct 8 ms 14172 KB Output is correct
19 Correct 8 ms 13996 KB Output is correct
20 Correct 4 ms 13952 KB Output is correct
21 Correct 4 ms 13720 KB Output is correct
22 Correct 8 ms 14028 KB Output is correct
23 Correct 8 ms 14156 KB Output is correct
24 Correct 11 ms 14632 KB Output is correct
25 Correct 11 ms 14408 KB Output is correct
26 Correct 10 ms 14220 KB Output is correct
27 Correct 5 ms 14044 KB Output is correct
28 Correct 12 ms 15376 KB Output is correct
29 Correct 25 ms 18000 KB Output is correct
30 Correct 10 ms 14888 KB Output is correct
31 Correct 15 ms 16196 KB Output is correct
32 Correct 10 ms 15424 KB Output is correct
33 Correct 47 ms 21992 KB Output is correct
34 Correct 47 ms 22012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13544 KB Output is correct
2 Correct 0 ms 13544 KB Output is correct
3 Correct 0 ms 13544 KB Output is correct
4 Correct 0 ms 13544 KB Output is correct
5 Correct 0 ms 13544 KB Output is correct
6 Correct 0 ms 13544 KB Output is correct
7 Correct 0 ms 13544 KB Output is correct
8 Correct 0 ms 13544 KB Output is correct
9 Correct 0 ms 13544 KB Output is correct
10 Correct 0 ms 13676 KB Output is correct
11 Correct 2 ms 13968 KB Output is correct
12 Correct 0 ms 13544 KB Output is correct
13 Correct 2 ms 13544 KB Output is correct
14 Correct 4 ms 14028 KB Output is correct
15 Correct 4 ms 14032 KB Output is correct
16 Correct 0 ms 13920 KB Output is correct
17 Correct 6 ms 14828 KB Output is correct
18 Correct 6 ms 14172 KB Output is correct
19 Correct 8 ms 13996 KB Output is correct
20 Correct 4 ms 13952 KB Output is correct
21 Correct 0 ms 13720 KB Output is correct
22 Correct 7 ms 14028 KB Output is correct
23 Correct 7 ms 14156 KB Output is correct
24 Correct 12 ms 14632 KB Output is correct
25 Correct 11 ms 14408 KB Output is correct
26 Correct 7 ms 14220 KB Output is correct
27 Correct 8 ms 14044 KB Output is correct
28 Correct 14 ms 15376 KB Output is correct
29 Correct 26 ms 18000 KB Output is correct
30 Correct 12 ms 14888 KB Output is correct
31 Correct 14 ms 16196 KB Output is correct
32 Correct 14 ms 15424 KB Output is correct
33 Correct 42 ms 21992 KB Output is correct
34 Correct 44 ms 22012 KB Output is correct
35 Correct 62 ms 23896 KB Output is correct
36 Correct 11 ms 15300 KB Output is correct
37 Correct 85 ms 28344 KB Output is correct
38 Correct 85 ms 28392 KB Output is correct
39 Correct 90 ms 28340 KB Output is correct
40 Correct 89 ms 28304 KB Output is correct
41 Correct 84 ms 28276 KB Output is correct
42 Correct 14 ms 14584 KB Output is correct
43 Correct 12 ms 14456 KB Output is correct
44 Correct 18 ms 14436 KB Output is correct
45 Correct 216 ms 48640 KB Output is correct
46 Correct 189 ms 48640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13544 KB Output is correct
2 Correct 0 ms 13544 KB Output is correct
3 Correct 0 ms 13544 KB Output is correct
4 Correct 1 ms 13544 KB Output is correct
5 Correct 0 ms 13544 KB Output is correct
6 Correct 0 ms 13544 KB Output is correct
7 Correct 0 ms 13544 KB Output is correct
8 Correct 0 ms 13544 KB Output is correct
9 Correct 0 ms 13544 KB Output is correct
10 Correct 0 ms 13676 KB Output is correct
11 Correct 0 ms 13968 KB Output is correct
12 Correct 0 ms 13544 KB Output is correct
13 Correct 0 ms 13544 KB Output is correct
14 Correct 4 ms 14028 KB Output is correct
15 Correct 4 ms 14032 KB Output is correct
16 Correct 0 ms 13920 KB Output is correct
17 Correct 7 ms 14828 KB Output is correct
18 Correct 8 ms 14172 KB Output is correct
19 Correct 8 ms 13996 KB Output is correct
20 Correct 5 ms 13952 KB Output is correct
21 Correct 3 ms 13720 KB Output is correct
22 Correct 7 ms 14028 KB Output is correct
23 Correct 8 ms 14156 KB Output is correct
24 Correct 8 ms 14632 KB Output is correct
25 Correct 10 ms 14408 KB Output is correct
26 Correct 6 ms 14220 KB Output is correct
27 Correct 6 ms 14044 KB Output is correct
28 Correct 15 ms 15376 KB Output is correct
29 Correct 28 ms 18000 KB Output is correct
30 Correct 12 ms 14888 KB Output is correct
31 Correct 18 ms 16196 KB Output is correct
32 Correct 14 ms 15424 KB Output is correct
33 Correct 45 ms 21992 KB Output is correct
34 Correct 45 ms 22012 KB Output is correct
35 Correct 54 ms 23896 KB Output is correct
36 Correct 9 ms 15300 KB Output is correct
37 Correct 81 ms 28344 KB Output is correct
38 Correct 78 ms 28392 KB Output is correct
39 Correct 85 ms 28340 KB Output is correct
40 Correct 85 ms 28304 KB Output is correct
41 Correct 92 ms 28276 KB Output is correct
42 Correct 14 ms 14584 KB Output is correct
43 Correct 17 ms 14456 KB Output is correct
44 Correct 13 ms 14436 KB Output is correct
45 Correct 206 ms 48640 KB Output is correct
46 Correct 205 ms 48640 KB Output is correct
47 Correct 326 ms 71632 KB Output is correct
48 Correct 176 ms 33108 KB Output is correct
49 Correct 133 ms 27144 KB Output is correct
50 Correct 142 ms 26700 KB Output is correct
51 Correct 248 ms 41084 KB Output is correct
52 Correct 257 ms 44180 KB Output is correct
53 Correct 154 ms 26700 KB Output is correct
54 Correct 85 ms 17180 KB Output is correct
55 Correct 103 ms 20788 KB Output is correct
56 Correct 118 ms 20916 KB Output is correct
57 Correct 327 ms 66016 KB Output is correct
58 Correct 117 ms 22132 KB Output is correct
59 Correct 139 ms 23440 KB Output is correct
60 Correct 154 ms 27976 KB Output is correct
61 Correct 127 ms 22896 KB Output is correct
62 Correct 299 ms 52472 KB Output is correct
63 Execution timed out 1000 ms 184044 KB Program timed out
64 Halted 0 ms 0 KB -