Submission #14414

# Submission time Handle Problem Language Result Execution time Memory
14414 2015-05-14T07:27:07 Z gs14004 Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 179220 KB
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
typedef pair<int,int> pi;
const int B = 150;

int m, n;

bool r_dir[30005][B], l_dir[30005][B];
bool vis[30005 * B];
vector<pi> graph[30005 * B];
priority_queue<pi,vector<pi>,greater<pi> > pq;

int dijkstra(int st, int ed){
    pq.push(pi(0,st));
    while (!pq.empty()) {
        pi t = pq.top();
        pq.pop();
        if(t.second == ed){
            return t.first;
        }
        if(vis[t.second]) continue;
        vis[t.second] = 1;
        for (auto &i : graph[t.second]){
            if(!vis[i.second]) pq.push(pi(i.first + t.first,i.second));
        }
        int px = t.second % n;
        int py = t.second / n;
        if(r_dir[px][py] && px + py < n){
            if(!vis[py * n + px + py]){
                pq.push(pi(1 + t.first,py * n + px + py));
            }
        }
        if(l_dir[px][py] && px - py >= 0){
            if(!vis[py * n + px - py]){
                pq.push(pi(1 + t.first,py * n + px - py));
            }
        }
        if(py){
            if(!vis[px]){
                pq.push(pi(t.first,px));
            }
        }
    }
    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 < B){
            r_dir[x][y] = 1;
            l_dir[x][y] = 1;
            graph[x].push_back(pi(0,x + n * y));
        }
        else{
            for (int j=1; x - j * y >= 0; j++) {
                graph[x].push_back(pi(j,x - j * y));
            }
            for (int j=1; x + j * y < n; j++) {
                graph[x].push_back(pi(j,x + j * y));
            }
        }
    }
    for (int i=1; i<B; 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];
        }
    }
    printf("%d",dijkstra(st,ed));
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 119884 KB Output is correct
2 Correct 12 ms 119884 KB Output is correct
3 Correct 22 ms 119884 KB Output is correct
4 Correct 13 ms 119884 KB Output is correct
5 Correct 17 ms 119884 KB Output is correct
6 Correct 30 ms 119884 KB Output is correct
7 Correct 15 ms 119884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 119884 KB Output is correct
2 Correct 12 ms 119884 KB Output is correct
3 Correct 11 ms 119884 KB Output is correct
4 Correct 14 ms 119884 KB Output is correct
5 Correct 12 ms 119884 KB Output is correct
6 Correct 21 ms 119884 KB Output is correct
7 Correct 13 ms 119884 KB Output is correct
8 Correct 12 ms 119884 KB Output is correct
9 Correct 18 ms 119884 KB Output is correct
10 Correct 22 ms 119884 KB Output is correct
11 Correct 29 ms 119884 KB Output is correct
12 Correct 16 ms 119884 KB Output is correct
13 Correct 21 ms 119884 KB Output is correct
14 Correct 26 ms 119884 KB Output is correct
15 Correct 27 ms 119884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 119884 KB Output is correct
2 Correct 14 ms 119884 KB Output is correct
3 Correct 26 ms 119884 KB Output is correct
4 Correct 12 ms 119884 KB Output is correct
5 Correct 8 ms 119884 KB Output is correct
6 Correct 19 ms 119884 KB Output is correct
7 Correct 29 ms 119884 KB Output is correct
8 Correct 12 ms 119884 KB Output is correct
9 Correct 8 ms 119884 KB Output is correct
10 Correct 12 ms 119884 KB Output is correct
11 Correct 17 ms 119884 KB Output is correct
12 Correct 14 ms 119884 KB Output is correct
13 Correct 17 ms 119884 KB Output is correct
14 Correct 17 ms 119884 KB Output is correct
15 Correct 21 ms 119884 KB Output is correct
16 Correct 11 ms 119884 KB Output is correct
17 Correct 27 ms 119884 KB Output is correct
18 Correct 23 ms 119884 KB Output is correct
19 Correct 15 ms 119884 KB Output is correct
20 Correct 28 ms 119884 KB Output is correct
21 Correct 8 ms 119884 KB Output is correct
22 Correct 31 ms 119884 KB Output is correct
23 Correct 24 ms 119884 KB Output is correct
24 Correct 23 ms 119884 KB Output is correct
25 Correct 36 ms 119884 KB Output is correct
26 Correct 16 ms 119884 KB Output is correct
27 Correct 25 ms 119884 KB Output is correct
28 Correct 15 ms 119884 KB Output is correct
29 Correct 27 ms 119884 KB Output is correct
30 Correct 15 ms 119884 KB Output is correct
31 Correct 16 ms 119884 KB Output is correct
32 Correct 23 ms 119884 KB Output is correct
33 Correct 34 ms 119884 KB Output is correct
34 Correct 28 ms 119884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 119884 KB Output is correct
2 Correct 22 ms 119884 KB Output is correct
3 Correct 18 ms 119884 KB Output is correct
4 Correct 22 ms 119884 KB Output is correct
5 Correct 18 ms 119884 KB Output is correct
6 Correct 16 ms 119884 KB Output is correct
7 Correct 21 ms 119884 KB Output is correct
8 Correct 21 ms 119884 KB Output is correct
9 Correct 19 ms 119884 KB Output is correct
10 Correct 15 ms 119884 KB Output is correct
11 Correct 15 ms 119884 KB Output is correct
12 Correct 14 ms 119884 KB Output is correct
13 Correct 16 ms 119884 KB Output is correct
14 Correct 15 ms 119884 KB Output is correct
15 Correct 22 ms 119884 KB Output is correct
16 Correct 11 ms 119884 KB Output is correct
17 Correct 22 ms 119884 KB Output is correct
18 Correct 23 ms 119884 KB Output is correct
19 Correct 24 ms 119884 KB Output is correct
20 Correct 24 ms 119884 KB Output is correct
21 Correct 31 ms 119884 KB Output is correct
22 Correct 23 ms 119884 KB Output is correct
23 Correct 20 ms 119884 KB Output is correct
24 Correct 25 ms 119884 KB Output is correct
25 Correct 27 ms 119884 KB Output is correct
26 Correct 20 ms 119884 KB Output is correct
27 Correct 32 ms 119884 KB Output is correct
28 Correct 29 ms 119884 KB Output is correct
29 Correct 25 ms 119884 KB Output is correct
30 Correct 15 ms 119884 KB Output is correct
31 Correct 16 ms 119884 KB Output is correct
32 Correct 21 ms 119884 KB Output is correct
33 Correct 43 ms 119884 KB Output is correct
34 Correct 20 ms 119884 KB Output is correct
35 Correct 23 ms 120412 KB Output is correct
36 Correct 24 ms 119884 KB Output is correct
37 Correct 36 ms 121048 KB Output is correct
38 Correct 24 ms 120700 KB Output is correct
39 Correct 23 ms 120544 KB Output is correct
40 Correct 21 ms 120544 KB Output is correct
41 Correct 21 ms 120720 KB Output is correct
42 Correct 34 ms 120276 KB Output is correct
43 Correct 31 ms 120276 KB Output is correct
44 Correct 29 ms 120272 KB Output is correct
45 Correct 129 ms 125236 KB Output is correct
46 Correct 76 ms 125240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 119884 KB Output is correct
2 Correct 18 ms 119884 KB Output is correct
3 Correct 22 ms 119884 KB Output is correct
4 Correct 30 ms 119884 KB Output is correct
5 Correct 18 ms 119884 KB Output is correct
6 Correct 21 ms 119884 KB Output is correct
7 Correct 25 ms 119884 KB Output is correct
8 Correct 16 ms 119884 KB Output is correct
9 Correct 12 ms 119884 KB Output is correct
10 Correct 26 ms 119884 KB Output is correct
11 Correct 22 ms 119884 KB Output is correct
12 Correct 17 ms 119884 KB Output is correct
13 Correct 11 ms 119884 KB Output is correct
14 Correct 19 ms 119884 KB Output is correct
15 Correct 17 ms 119884 KB Output is correct
16 Correct 12 ms 119884 KB Output is correct
17 Correct 11 ms 119884 KB Output is correct
18 Correct 24 ms 119884 KB Output is correct
19 Correct 22 ms 119884 KB Output is correct
20 Correct 24 ms 119884 KB Output is correct
21 Correct 12 ms 119884 KB Output is correct
22 Correct 15 ms 119884 KB Output is correct
23 Correct 16 ms 119884 KB Output is correct
24 Correct 22 ms 119884 KB Output is correct
25 Correct 20 ms 119884 KB Output is correct
26 Correct 12 ms 119884 KB Output is correct
27 Correct 12 ms 119884 KB Output is correct
28 Correct 26 ms 119884 KB Output is correct
29 Correct 27 ms 119884 KB Output is correct
30 Correct 21 ms 119884 KB Output is correct
31 Correct 20 ms 119884 KB Output is correct
32 Correct 19 ms 119884 KB Output is correct
33 Correct 31 ms 119884 KB Output is correct
34 Correct 20 ms 119884 KB Output is correct
35 Correct 47 ms 120412 KB Output is correct
36 Correct 13 ms 119884 KB Output is correct
37 Correct 36 ms 121048 KB Output is correct
38 Correct 29 ms 120700 KB Output is correct
39 Correct 26 ms 120544 KB Output is correct
40 Correct 31 ms 120544 KB Output is correct
41 Correct 21 ms 120720 KB Output is correct
42 Correct 24 ms 120276 KB Output is correct
43 Correct 28 ms 120276 KB Output is correct
44 Correct 34 ms 120272 KB Output is correct
45 Correct 125 ms 125236 KB Output is correct
46 Correct 89 ms 125240 KB Output is correct
47 Correct 59 ms 125348 KB Output is correct
48 Correct 66 ms 120940 KB Output is correct
49 Correct 63 ms 120808 KB Output is correct
50 Correct 62 ms 120676 KB Output is correct
51 Correct 82 ms 122340 KB Output is correct
52 Correct 83 ms 122364 KB Output is correct
53 Correct 68 ms 119884 KB Output is correct
54 Correct 66 ms 119884 KB Output is correct
55 Correct 63 ms 119884 KB Output is correct
56 Correct 67 ms 120808 KB Output is correct
57 Correct 71 ms 119884 KB Output is correct
58 Correct 71 ms 120656 KB Output is correct
59 Correct 72 ms 120272 KB Output is correct
60 Correct 61 ms 120636 KB Output is correct
61 Correct 65 ms 120480 KB Output is correct
62 Correct 89 ms 122260 KB Output is correct
63 Correct 396 ms 157900 KB Output is correct
64 Correct 441 ms 171172 KB Output is correct
65 Execution timed out 1000 ms 179220 KB Program timed out
66 Halted 0 ms 0 KB -