Submission #23432

# Submission time Handle Problem Language Result Execution time Memory
23432 2017-05-09T09:40:09 Z rubabredwan Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 36056 KB
/* Bismillahir Rahmanir Rahim */

#include <bits/stdc++.h>

using namespace std;

const int N = 30005;
const int M = 250;
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 3 ms 33436 KB Output is correct
2 Correct 3 ms 33436 KB Output is correct
3 Correct 3 ms 33436 KB Output is correct
4 Correct 9 ms 33436 KB Output is correct
5 Correct 6 ms 33436 KB Output is correct
6 Correct 6 ms 33436 KB Output is correct
7 Correct 13 ms 33436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 33436 KB Output is correct
2 Correct 6 ms 33436 KB Output is correct
3 Correct 6 ms 33436 KB Output is correct
4 Correct 6 ms 33436 KB Output is correct
5 Correct 13 ms 33436 KB Output is correct
6 Correct 6 ms 33436 KB Output is correct
7 Correct 6 ms 33436 KB Output is correct
8 Correct 9 ms 33436 KB Output is correct
9 Correct 0 ms 33436 KB Output is correct
10 Correct 0 ms 33436 KB Output is correct
11 Correct 3 ms 33576 KB Output is correct
12 Correct 0 ms 33436 KB Output is correct
13 Correct 3 ms 33436 KB Output is correct
14 Correct 6 ms 33576 KB Output is correct
15 Correct 13 ms 33576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33436 KB Output is correct
2 Correct 9 ms 33436 KB Output is correct
3 Correct 0 ms 33436 KB Output is correct
4 Correct 6 ms 33436 KB Output is correct
5 Correct 13 ms 33436 KB Output is correct
6 Correct 9 ms 33436 KB Output is correct
7 Correct 6 ms 33436 KB Output is correct
8 Correct 6 ms 33436 KB Output is correct
9 Correct 0 ms 33436 KB Output is correct
10 Correct 6 ms 33436 KB Output is correct
11 Correct 13 ms 33576 KB Output is correct
12 Correct 6 ms 33436 KB Output is correct
13 Correct 16 ms 33436 KB Output is correct
14 Correct 6 ms 33576 KB Output is correct
15 Correct 3 ms 33576 KB Output is correct
16 Correct 9 ms 33436 KB Output is correct
17 Correct 3 ms 33584 KB Output is correct
18 Correct 0 ms 33436 KB Output is correct
19 Correct 0 ms 33436 KB Output is correct
20 Correct 9 ms 33568 KB Output is correct
21 Correct 3 ms 33436 KB Output is correct
22 Correct 6 ms 33436 KB Output is correct
23 Correct 0 ms 33436 KB Output is correct
24 Correct 6 ms 33436 KB Output is correct
25 Correct 6 ms 33436 KB Output is correct
26 Correct 6 ms 33436 KB Output is correct
27 Correct 9 ms 33436 KB Output is correct
28 Correct 13 ms 33568 KB Output is correct
29 Correct 6 ms 33436 KB Output is correct
30 Correct 6 ms 33436 KB Output is correct
31 Correct 3 ms 33436 KB Output is correct
32 Correct 3 ms 33436 KB Output is correct
33 Correct 23 ms 33576 KB Output is correct
34 Correct 9 ms 33576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 33436 KB Output is correct
2 Correct 6 ms 33436 KB Output is correct
3 Correct 6 ms 33436 KB Output is correct
4 Correct 0 ms 33436 KB Output is correct
5 Correct 3 ms 33436 KB Output is correct
6 Correct 3 ms 33436 KB Output is correct
7 Correct 6 ms 33436 KB Output is correct
8 Correct 6 ms 33436 KB Output is correct
9 Correct 6 ms 33436 KB Output is correct
10 Correct 6 ms 33436 KB Output is correct
11 Correct 9 ms 33576 KB Output is correct
12 Correct 6 ms 33436 KB Output is correct
13 Correct 6 ms 33436 KB Output is correct
14 Correct 6 ms 33576 KB Output is correct
15 Correct 9 ms 33576 KB Output is correct
16 Correct 6 ms 33436 KB Output is correct
17 Correct 13 ms 33584 KB Output is correct
18 Correct 13 ms 33436 KB Output is correct
19 Correct 6 ms 33436 KB Output is correct
20 Correct 9 ms 33568 KB Output is correct
21 Correct 9 ms 33436 KB Output is correct
22 Correct 6 ms 33436 KB Output is correct
23 Correct 13 ms 33436 KB Output is correct
24 Correct 13 ms 33436 KB Output is correct
25 Correct 0 ms 33436 KB Output is correct
26 Correct 6 ms 33436 KB Output is correct
27 Correct 13 ms 33436 KB Output is correct
28 Correct 9 ms 33568 KB Output is correct
29 Correct 9 ms 33436 KB Output is correct
30 Correct 6 ms 33436 KB Output is correct
31 Correct 6 ms 33436 KB Output is correct
32 Correct 16 ms 33436 KB Output is correct
33 Correct 16 ms 33576 KB Output is correct
34 Correct 9 ms 33576 KB Output is correct
35 Correct 23 ms 33904 KB Output is correct
36 Correct 3 ms 33568 KB Output is correct
37 Correct 26 ms 34084 KB Output is correct
38 Correct 26 ms 33852 KB Output is correct
39 Correct 26 ms 33848 KB Output is correct
40 Correct 29 ms 33852 KB Output is correct
41 Correct 26 ms 33852 KB Output is correct
42 Correct 16 ms 33712 KB Output is correct
43 Correct 9 ms 33712 KB Output is correct
44 Correct 13 ms 33708 KB Output is correct
45 Correct 59 ms 34272 KB Output is correct
46 Correct 63 ms 34276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33436 KB Output is correct
2 Correct 16 ms 33436 KB Output is correct
3 Correct 9 ms 33436 KB Output is correct
4 Correct 9 ms 33436 KB Output is correct
5 Correct 9 ms 33436 KB Output is correct
6 Correct 3 ms 33436 KB Output is correct
7 Correct 6 ms 33436 KB Output is correct
8 Correct 6 ms 33436 KB Output is correct
9 Correct 9 ms 33436 KB Output is correct
10 Correct 6 ms 33436 KB Output is correct
11 Correct 0 ms 33576 KB Output is correct
12 Correct 6 ms 33436 KB Output is correct
13 Correct 13 ms 33436 KB Output is correct
14 Correct 0 ms 33576 KB Output is correct
15 Correct 0 ms 33576 KB Output is correct
16 Correct 3 ms 33436 KB Output is correct
17 Correct 13 ms 33584 KB Output is correct
18 Correct 3 ms 33436 KB Output is correct
19 Correct 6 ms 33436 KB Output is correct
20 Correct 3 ms 33568 KB Output is correct
21 Correct 6 ms 33436 KB Output is correct
22 Correct 9 ms 33436 KB Output is correct
23 Correct 9 ms 33436 KB Output is correct
24 Correct 13 ms 33436 KB Output is correct
25 Correct 6 ms 33436 KB Output is correct
26 Correct 9 ms 33436 KB Output is correct
27 Correct 6 ms 33436 KB Output is correct
28 Correct 9 ms 33568 KB Output is correct
29 Correct 16 ms 33436 KB Output is correct
30 Correct 3 ms 33436 KB Output is correct
31 Correct 3 ms 33436 KB Output is correct
32 Correct 6 ms 33436 KB Output is correct
33 Correct 19 ms 33576 KB Output is correct
34 Correct 19 ms 33576 KB Output is correct
35 Correct 39 ms 33904 KB Output is correct
36 Correct 6 ms 33568 KB Output is correct
37 Correct 39 ms 34084 KB Output is correct
38 Correct 36 ms 33852 KB Output is correct
39 Correct 23 ms 33848 KB Output is correct
40 Correct 19 ms 33852 KB Output is correct
41 Correct 26 ms 33852 KB Output is correct
42 Correct 23 ms 33712 KB Output is correct
43 Correct 6 ms 33712 KB Output is correct
44 Correct 9 ms 33708 KB Output is correct
45 Correct 79 ms 34272 KB Output is correct
46 Correct 73 ms 34276 KB Output is correct
47 Correct 99 ms 34440 KB Output is correct
48 Correct 16 ms 33964 KB Output is correct
49 Correct 19 ms 33964 KB Output is correct
50 Correct 6 ms 33832 KB Output is correct
51 Correct 53 ms 34688 KB Output is correct
52 Correct 69 ms 34692 KB Output is correct
53 Correct 29 ms 34096 KB Output is correct
54 Correct 13 ms 33436 KB Output is correct
55 Correct 9 ms 33436 KB Output is correct
56 Correct 19 ms 34360 KB Output is correct
57 Correct 66 ms 33568 KB Output is correct
58 Correct 23 ms 33708 KB Output is correct
59 Correct 23 ms 33708 KB Output is correct
60 Correct 26 ms 33716 KB Output is correct
61 Correct 19 ms 33724 KB Output is correct
62 Correct 56 ms 34360 KB Output is correct
63 Correct 113 ms 36056 KB Output is correct
64 Correct 173 ms 36020 KB Output is correct
65 Correct 509 ms 36044 KB Output is correct
66 Execution timed out 1000 ms 34272 KB Execution timed out
67 Halted 0 ms 0 KB -