답안 #23433

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
23433 2017-05-09T09:40:38 Z rubabredwan Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
669 ms 24332 KB
/* Bismillahir Rahmanir Rahim */

#include <bits/stdc++.h>

using namespace std;

const int N = 30005;
const int M = 150;
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]);
                                                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21712 KB Output is correct
2 Correct 9 ms 21712 KB Output is correct
3 Correct 3 ms 21712 KB Output is correct
4 Correct 0 ms 21712 KB Output is correct
5 Correct 0 ms 21712 KB Output is correct
6 Correct 0 ms 21712 KB Output is correct
7 Correct 3 ms 21712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 21712 KB Output is correct
2 Correct 3 ms 21712 KB Output is correct
3 Correct 6 ms 21712 KB Output is correct
4 Correct 9 ms 21712 KB Output is correct
5 Correct 0 ms 21712 KB Output is correct
6 Correct 0 ms 21712 KB Output is correct
7 Correct 3 ms 21712 KB Output is correct
8 Correct 3 ms 21712 KB Output is correct
9 Correct 3 ms 21712 KB Output is correct
10 Correct 3 ms 21712 KB Output is correct
11 Correct 0 ms 21852 KB Output is correct
12 Correct 0 ms 21712 KB Output is correct
13 Correct 3 ms 21712 KB Output is correct
14 Correct 0 ms 21852 KB Output is correct
15 Correct 6 ms 21852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 21712 KB Output is correct
2 Correct 3 ms 21712 KB Output is correct
3 Correct 3 ms 21712 KB Output is correct
4 Correct 9 ms 21712 KB Output is correct
5 Correct 0 ms 21712 KB Output is correct
6 Correct 3 ms 21712 KB Output is correct
7 Correct 6 ms 21712 KB Output is correct
8 Correct 0 ms 21712 KB Output is correct
9 Correct 3 ms 21712 KB Output is correct
10 Correct 3 ms 21712 KB Output is correct
11 Correct 6 ms 21852 KB Output is correct
12 Correct 6 ms 21712 KB Output is correct
13 Correct 3 ms 21712 KB Output is correct
14 Correct 6 ms 21852 KB Output is correct
15 Correct 3 ms 21852 KB Output is correct
16 Correct 3 ms 21712 KB Output is correct
17 Correct 9 ms 21860 KB Output is correct
18 Correct 3 ms 21712 KB Output is correct
19 Correct 6 ms 21712 KB Output is correct
20 Correct 3 ms 21844 KB Output is correct
21 Correct 3 ms 21712 KB Output is correct
22 Correct 0 ms 21712 KB Output is correct
23 Correct 6 ms 21712 KB Output is correct
24 Correct 6 ms 21712 KB Output is correct
25 Correct 3 ms 21712 KB Output is correct
26 Correct 9 ms 21712 KB Output is correct
27 Correct 6 ms 21712 KB Output is correct
28 Correct 9 ms 21844 KB Output is correct
29 Correct 3 ms 21712 KB Output is correct
30 Correct 9 ms 21712 KB Output is correct
31 Correct 9 ms 21712 KB Output is correct
32 Correct 6 ms 21712 KB Output is correct
33 Correct 13 ms 21852 KB Output is correct
34 Correct 23 ms 21852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21712 KB Output is correct
2 Correct 0 ms 21712 KB Output is correct
3 Correct 3 ms 21712 KB Output is correct
4 Correct 0 ms 21712 KB Output is correct
5 Correct 6 ms 21712 KB Output is correct
6 Correct 3 ms 21712 KB Output is correct
7 Correct 3 ms 21712 KB Output is correct
8 Correct 3 ms 21712 KB Output is correct
9 Correct 6 ms 21712 KB Output is correct
10 Correct 6 ms 21712 KB Output is correct
11 Correct 3 ms 21852 KB Output is correct
12 Correct 6 ms 21712 KB Output is correct
13 Correct 0 ms 21712 KB Output is correct
14 Correct 6 ms 21852 KB Output is correct
15 Correct 0 ms 21852 KB Output is correct
16 Correct 6 ms 21712 KB Output is correct
17 Correct 6 ms 21860 KB Output is correct
18 Correct 6 ms 21712 KB Output is correct
19 Correct 0 ms 21712 KB Output is correct
20 Correct 9 ms 21844 KB Output is correct
21 Correct 0 ms 21712 KB Output is correct
22 Correct 6 ms 21712 KB Output is correct
23 Correct 9 ms 21712 KB Output is correct
24 Correct 13 ms 21712 KB Output is correct
25 Correct 3 ms 21712 KB Output is correct
26 Correct 6 ms 21712 KB Output is correct
27 Correct 9 ms 21712 KB Output is correct
28 Correct 6 ms 21844 KB Output is correct
29 Correct 6 ms 21712 KB Output is correct
30 Correct 9 ms 21712 KB Output is correct
31 Correct 6 ms 21712 KB Output is correct
32 Correct 6 ms 21712 KB Output is correct
33 Correct 13 ms 21852 KB Output is correct
34 Correct 13 ms 21852 KB Output is correct
35 Correct 19 ms 21976 KB Output is correct
36 Correct 6 ms 21844 KB Output is correct
37 Correct 19 ms 22164 KB Output is correct
38 Correct 23 ms 22128 KB Output is correct
39 Correct 26 ms 22124 KB Output is correct
40 Correct 23 ms 22128 KB Output is correct
41 Correct 9 ms 22128 KB Output is correct
42 Correct 3 ms 21988 KB Output is correct
43 Correct 13 ms 21988 KB Output is correct
44 Correct 13 ms 21984 KB Output is correct
45 Correct 43 ms 22352 KB Output is correct
46 Correct 36 ms 22356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21712 KB Output is correct
2 Correct 3 ms 21712 KB Output is correct
3 Correct 6 ms 21712 KB Output is correct
4 Correct 0 ms 21712 KB Output is correct
5 Correct 3 ms 21712 KB Output is correct
6 Correct 3 ms 21712 KB Output is correct
7 Correct 6 ms 21712 KB Output is correct
8 Correct 6 ms 21712 KB Output is correct
9 Correct 0 ms 21712 KB Output is correct
10 Correct 9 ms 21712 KB Output is correct
11 Correct 3 ms 21852 KB Output is correct
12 Correct 3 ms 21712 KB Output is correct
13 Correct 0 ms 21712 KB Output is correct
14 Correct 6 ms 21852 KB Output is correct
15 Correct 6 ms 21852 KB Output is correct
16 Correct 6 ms 21712 KB Output is correct
17 Correct 3 ms 21860 KB Output is correct
18 Correct 3 ms 21712 KB Output is correct
19 Correct 3 ms 21712 KB Output is correct
20 Correct 3 ms 21844 KB Output is correct
21 Correct 3 ms 21712 KB Output is correct
22 Correct 9 ms 21712 KB Output is correct
23 Correct 0 ms 21712 KB Output is correct
24 Correct 3 ms 21712 KB Output is correct
25 Correct 3 ms 21712 KB Output is correct
26 Correct 6 ms 21712 KB Output is correct
27 Correct 3 ms 21712 KB Output is correct
28 Correct 6 ms 21844 KB Output is correct
29 Correct 6 ms 21712 KB Output is correct
30 Correct 6 ms 21712 KB Output is correct
31 Correct 3 ms 21712 KB Output is correct
32 Correct 6 ms 21712 KB Output is correct
33 Correct 16 ms 21852 KB Output is correct
34 Correct 16 ms 21852 KB Output is correct
35 Correct 19 ms 21976 KB Output is correct
36 Correct 3 ms 21844 KB Output is correct
37 Correct 19 ms 22164 KB Output is correct
38 Correct 26 ms 22128 KB Output is correct
39 Correct 23 ms 22124 KB Output is correct
40 Correct 29 ms 22128 KB Output is correct
41 Correct 19 ms 22128 KB Output is correct
42 Correct 13 ms 21988 KB Output is correct
43 Correct 9 ms 21988 KB Output is correct
44 Correct 13 ms 21984 KB Output is correct
45 Correct 36 ms 22352 KB Output is correct
46 Correct 39 ms 22356 KB Output is correct
47 Correct 83 ms 22716 KB Output is correct
48 Correct 13 ms 22240 KB Output is correct
49 Correct 9 ms 22240 KB Output is correct
50 Correct 9 ms 22108 KB Output is correct
51 Correct 53 ms 22964 KB Output is correct
52 Correct 69 ms 22968 KB Output is correct
53 Correct 29 ms 22372 KB Output is correct
54 Correct 6 ms 21712 KB Output is correct
55 Correct 6 ms 21712 KB Output is correct
56 Correct 16 ms 22636 KB Output is correct
57 Correct 69 ms 21844 KB Output is correct
58 Correct 23 ms 21984 KB Output is correct
59 Correct 29 ms 21984 KB Output is correct
60 Correct 26 ms 21992 KB Output is correct
61 Correct 23 ms 22000 KB Output is correct
62 Correct 53 ms 22636 KB Output is correct
63 Correct 49 ms 24332 KB Output is correct
64 Correct 56 ms 24296 KB Output is correct
65 Correct 193 ms 24320 KB Output is correct
66 Correct 616 ms 24276 KB Output is correct
67 Correct 669 ms 24276 KB Output is correct