Submission #23431

# Submission time Handle Problem Language Result Execution time Memory
23431 2017-05-09T09:37:08 Z rubabredwan Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
863 ms 30192 KB
/* Bismillahir Rahmanir Rahim */

#include <bits/stdc++.h>

using namespace std;

const int N = 30005;
const int M = 200;
const int oo = 1e9;

struct data{
    int cost, pos, b;
    bool operator < (const data &p) const{
        return cost > p.cost;
    }
    data () {}
    data (int _cost, int _pos, int _b){
        cost = _cost;
        pos = _pos;
        b = _b;
    }
};

int dis[N][M+10];
int n, m, B[N], P[N];
vector<int>ps[N];
priority_queue<data>q;

void propagate(int pos, int sz, int pst){
    int ds = pst;
    for(int i=pos;i>=0;i-=sz){
        if(dis[i][0] > ds){
            dis[i][0] = ds;
            q.push(data(ds, i, 0));
        }
        ++ds;
    }
    ds = pst;
    for(int i=pos;i<n;i+=sz){
        if(dis[i][0] > ds){
            dis[i][0] = ds;
            q.push(data(ds, i, 0));
        }
        ++ds;
    }
}

int solve(){
    for(int i=0;i<N;i++) for(int j=0;j<=M;j++) dis[i][j] = oo;
    if(B[1] <= M){
        dis[P[1]][B[1]] = 0;
        q.push(data(0, P[1], B[1]));
    }
    else propagate(P[1], B[1], 0);
    while(!q.empty()){
        data u = q.top(); q.pop();
        int pos = u.pos, sz = u.b;
        for(auto u : ps[pos]){
            if(B[u] <= M){
                if(dis[pos][B[u]] > dis[pos][sz]){
                    dis[pos][B[u]] = dis[pos][sz];
                    q.push(data(dis[pos][sz], pos, B[u]));
                }
            }
            else propagate(pos, B[u], dis[pos][sz]);
        }
        ps[pos].clear();
        if(pos - sz >= 0 && dis[pos-sz][sz] > dis[pos][sz] + 1){
            dis[pos-sz][sz] = dis[pos][sz] + 1;
            q.push(data(dis[pos-sz][sz], pos-sz, sz));
        }
        if(pos + sz <  n && dis[pos+sz][sz] > dis[pos][sz] + 1){
            dis[pos+sz][sz] = dis[pos][sz] + 1;
            q.push(data(dis[pos+sz][sz], pos+sz, sz));
        }
    }
    int ret = oo;
    for(int i=0;i<=M;i++) ret = min(ret, dis[P[2]][i]);
    return ret == oo ? -1 : ret;
}

int main(){
    scanf("%d %d", &n, &m);
    for(int i=1;i<=m;i++) scanf("%d %d", &P[i], &B[i]);
    for(int i=1;i<=m;i++) ps[P[i]].push_back(i);
    int ret = solve();
    printf("%d\n", ret);
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:83:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
                           ^
skyscraper.cpp:84:55: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=m;i++) scanf("%d %d", &P[i], &B[i]);
                                                       ^
# Verdict Execution time Memory Grader output
1 Correct 13 ms 27572 KB Output is correct
2 Correct 9 ms 27572 KB Output is correct
3 Correct 9 ms 27572 KB Output is correct
4 Correct 6 ms 27572 KB Output is correct
5 Correct 3 ms 27572 KB Output is correct
6 Correct 3 ms 27572 KB Output is correct
7 Correct 6 ms 27572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 27572 KB Output is correct
2 Correct 3 ms 27572 KB Output is correct
3 Correct 6 ms 27572 KB Output is correct
4 Correct 3 ms 27572 KB Output is correct
5 Correct 6 ms 27572 KB Output is correct
6 Correct 0 ms 27572 KB Output is correct
7 Correct 3 ms 27572 KB Output is correct
8 Correct 3 ms 27572 KB Output is correct
9 Correct 0 ms 27572 KB Output is correct
10 Correct 0 ms 27572 KB Output is correct
11 Correct 9 ms 27712 KB Output is correct
12 Correct 0 ms 27572 KB Output is correct
13 Correct 3 ms 27572 KB Output is correct
14 Correct 3 ms 27712 KB Output is correct
15 Correct 0 ms 27712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 27572 KB Output is correct
2 Correct 9 ms 27572 KB Output is correct
3 Correct 6 ms 27572 KB Output is correct
4 Correct 13 ms 27572 KB Output is correct
5 Correct 9 ms 27572 KB Output is correct
6 Correct 9 ms 27572 KB Output is correct
7 Correct 0 ms 27572 KB Output is correct
8 Correct 9 ms 27572 KB Output is correct
9 Correct 3 ms 27572 KB Output is correct
10 Correct 3 ms 27572 KB Output is correct
11 Correct 3 ms 27712 KB Output is correct
12 Correct 6 ms 27572 KB Output is correct
13 Correct 6 ms 27572 KB Output is correct
14 Correct 6 ms 27712 KB Output is correct
15 Correct 0 ms 27712 KB Output is correct
16 Correct 3 ms 27572 KB Output is correct
17 Correct 9 ms 27720 KB Output is correct
18 Correct 3 ms 27572 KB Output is correct
19 Correct 3 ms 27572 KB Output is correct
20 Correct 6 ms 27704 KB Output is correct
21 Correct 6 ms 27572 KB Output is correct
22 Correct 3 ms 27572 KB Output is correct
23 Correct 6 ms 27572 KB Output is correct
24 Correct 6 ms 27572 KB Output is correct
25 Correct 6 ms 27572 KB Output is correct
26 Correct 9 ms 27572 KB Output is correct
27 Correct 6 ms 27572 KB Output is correct
28 Correct 9 ms 27704 KB Output is correct
29 Correct 6 ms 27572 KB Output is correct
30 Correct 3 ms 27572 KB Output is correct
31 Correct 6 ms 27572 KB Output is correct
32 Correct 9 ms 27572 KB Output is correct
33 Correct 23 ms 27712 KB Output is correct
34 Correct 13 ms 27712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 27572 KB Output is correct
2 Correct 6 ms 27572 KB Output is correct
3 Correct 3 ms 27572 KB Output is correct
4 Correct 9 ms 27572 KB Output is correct
5 Correct 13 ms 27572 KB Output is correct
6 Correct 3 ms 27572 KB Output is correct
7 Correct 3 ms 27572 KB Output is correct
8 Correct 9 ms 27572 KB Output is correct
9 Correct 3 ms 27572 KB Output is correct
10 Correct 3 ms 27572 KB Output is correct
11 Correct 6 ms 27712 KB Output is correct
12 Correct 6 ms 27572 KB Output is correct
13 Correct 6 ms 27572 KB Output is correct
14 Correct 3 ms 27712 KB Output is correct
15 Correct 0 ms 27712 KB Output is correct
16 Correct 9 ms 27572 KB Output is correct
17 Correct 6 ms 27720 KB Output is correct
18 Correct 0 ms 27572 KB Output is correct
19 Correct 6 ms 27572 KB Output is correct
20 Correct 0 ms 27704 KB Output is correct
21 Correct 0 ms 27572 KB Output is correct
22 Correct 6 ms 27572 KB Output is correct
23 Correct 6 ms 27572 KB Output is correct
24 Correct 0 ms 27572 KB Output is correct
25 Correct 3 ms 27572 KB Output is correct
26 Correct 6 ms 27572 KB Output is correct
27 Correct 6 ms 27572 KB Output is correct
28 Correct 9 ms 27704 KB Output is correct
29 Correct 13 ms 27572 KB Output is correct
30 Correct 6 ms 27572 KB Output is correct
31 Correct 6 ms 27572 KB Output is correct
32 Correct 9 ms 27572 KB Output is correct
33 Correct 19 ms 27712 KB Output is correct
34 Correct 9 ms 27712 KB Output is correct
35 Correct 16 ms 28040 KB Output is correct
36 Correct 0 ms 27704 KB Output is correct
37 Correct 29 ms 28220 KB Output is correct
38 Correct 26 ms 27988 KB Output is correct
39 Correct 33 ms 27984 KB Output is correct
40 Correct 23 ms 27988 KB Output is correct
41 Correct 29 ms 27988 KB Output is correct
42 Correct 16 ms 27848 KB Output is correct
43 Correct 6 ms 27848 KB Output is correct
44 Correct 9 ms 27844 KB Output is correct
45 Correct 46 ms 28408 KB Output is correct
46 Correct 53 ms 28412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 27572 KB Output is correct
2 Correct 9 ms 27572 KB Output is correct
3 Correct 9 ms 27572 KB Output is correct
4 Correct 3 ms 27572 KB Output is correct
5 Correct 6 ms 27572 KB Output is correct
6 Correct 6 ms 27572 KB Output is correct
7 Correct 3 ms 27572 KB Output is correct
8 Correct 6 ms 27572 KB Output is correct
9 Correct 6 ms 27572 KB Output is correct
10 Correct 0 ms 27572 KB Output is correct
11 Correct 13 ms 27712 KB Output is correct
12 Correct 6 ms 27572 KB Output is correct
13 Correct 3 ms 27572 KB Output is correct
14 Correct 3 ms 27712 KB Output is correct
15 Correct 3 ms 27712 KB Output is correct
16 Correct 6 ms 27572 KB Output is correct
17 Correct 9 ms 27720 KB Output is correct
18 Correct 9 ms 27572 KB Output is correct
19 Correct 3 ms 27572 KB Output is correct
20 Correct 3 ms 27704 KB Output is correct
21 Correct 9 ms 27572 KB Output is correct
22 Correct 3 ms 27572 KB Output is correct
23 Correct 9 ms 27572 KB Output is correct
24 Correct 6 ms 27572 KB Output is correct
25 Correct 6 ms 27572 KB Output is correct
26 Correct 6 ms 27572 KB Output is correct
27 Correct 6 ms 27572 KB Output is correct
28 Correct 3 ms 27704 KB Output is correct
29 Correct 6 ms 27572 KB Output is correct
30 Correct 0 ms 27572 KB Output is correct
31 Correct 6 ms 27572 KB Output is correct
32 Correct 9 ms 27572 KB Output is correct
33 Correct 9 ms 27712 KB Output is correct
34 Correct 16 ms 27712 KB Output is correct
35 Correct 16 ms 28040 KB Output is correct
36 Correct 6 ms 27704 KB Output is correct
37 Correct 26 ms 28220 KB Output is correct
38 Correct 16 ms 27988 KB Output is correct
39 Correct 26 ms 27984 KB Output is correct
40 Correct 29 ms 27988 KB Output is correct
41 Correct 26 ms 27988 KB Output is correct
42 Correct 16 ms 27848 KB Output is correct
43 Correct 13 ms 27848 KB Output is correct
44 Correct 6 ms 27844 KB Output is correct
45 Correct 56 ms 28408 KB Output is correct
46 Correct 53 ms 28412 KB Output is correct
47 Correct 99 ms 28576 KB Output is correct
48 Correct 13 ms 28100 KB Output is correct
49 Correct 9 ms 28100 KB Output is correct
50 Correct 9 ms 27968 KB Output is correct
51 Correct 53 ms 28824 KB Output is correct
52 Correct 59 ms 28828 KB Output is correct
53 Correct 26 ms 28232 KB Output is correct
54 Correct 6 ms 27572 KB Output is correct
55 Correct 6 ms 27572 KB Output is correct
56 Correct 13 ms 28496 KB Output is correct
57 Correct 66 ms 27704 KB Output is correct
58 Correct 26 ms 27844 KB Output is correct
59 Correct 26 ms 27844 KB Output is correct
60 Correct 33 ms 27852 KB Output is correct
61 Correct 33 ms 27860 KB Output is correct
62 Correct 63 ms 28496 KB Output is correct
63 Correct 46 ms 30192 KB Output is correct
64 Correct 59 ms 30156 KB Output is correct
65 Correct 366 ms 30180 KB Output is correct
66 Correct 859 ms 30136 KB Output is correct
67 Correct 863 ms 30136 KB Output is correct