답안 #31735

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
31735 2017-09-03T04:38:52 Z top34051 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
249 ms 100624 KB
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define maxn 30005
struct node {
    int x,val;
    node(int _x = 0,int _val = 0) {
        x = _x; val = _val;
    }
    bool operator < (node a) const {
        return a.val<val;
    }
};
int n,m,st,ft;
int mem[maxn];
int last[maxn];
bool ok[175][maxn];
vector<pair<int,int> > from[maxn];
priority_queue<node> heap;
main() {
    int i,j,x,y,pos,val,cnt;
    scanf("%d%d",&n,&m);
    for(i=0;i<m;i++) {
        scanf("%d%d",&pos,&val);
        if(i==0) st = pos;
        if(i==1) ft = pos;
        if(val>sqrt(n)) {
            x = pos; cnt = 0;
            while(x<n) {
                from[pos].push_back({x,cnt});
//                printf("1) %d -> %d (%d)\n",pos,x,cnt);
                x += val; cnt++;
            }
            x = pos; cnt = 0;
            while(x>=0) {
                from[pos].push_back({x,cnt});
//                printf("1) %d -> %d (%d)\n",pos,x,cnt);
                x -= val; cnt++;
            }
        }
        else ok[val][pos] = 1;
    }
    for(i=1;i<=sqrt(n);i++) {
        memset(last,-1,sizeof(last));
        for(x=0;x<n;x++) {
            if(last[x%i]!=-1) {
                from[last[x%i]].push_back({x,(x-last[x%i])/i});
//                printf("2) %d -> %d (%d)\n",last[x%i],x,(x-last[x%i])/i);
            }
            if(ok[i][x]) last[x%i] = x;
        }
        memset(last,-1,sizeof(last));
        for(x=n-1;x>=0;x--) {
            if(last[x%i]!=-1) {
                from[last[x%i]].push_back({x,(last[x%i]-x)/i});
//                printf("2) %d -> %d (%d)\n",last[x%i],x,(last[x%i]-x)/i);
            }
            if(ok[i][x]) last[x%i] = x;
        }
    }
    for(i=0;i<n;i++) mem[i] = inf;
    mem[st] = 0;
    heap.push(node(st,0));
    while(!heap.empty()) {
        x = heap.top().x; val = heap.top().val; heap.pop();
//        printf("%d : %d\n",x,val);
        if(val!=mem[x]) continue;
        for(i=0;i<from[x].size();i++) {
            y = from[x][i].first; val = from[x][i].second;
            if(mem[y] > mem[x] + val) {
                mem[y] = mem[x] + val;
                heap.push(node(y,mem[y]));
            }
        }
    }
    if(mem[ft]==inf) printf("-1");
    else printf("%d",mem[ft]);
}

Compilation message

skyscraper.cpp:20:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:68:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<from[x].size();i++) {
                  ^
skyscraper.cpp:21:11: warning: unused variable 'j' [-Wunused-variable]
     int i,j,x,y,pos,val,cnt;
           ^
skyscraper.cpp:22:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
                        ^
skyscraper.cpp:24:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&pos,&val);
                                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8096 KB Output is correct
2 Correct 0 ms 8096 KB Output is correct
3 Correct 0 ms 8096 KB Output is correct
4 Correct 0 ms 8096 KB Output is correct
5 Correct 0 ms 8096 KB Output is correct
6 Correct 0 ms 8096 KB Output is correct
7 Correct 0 ms 8096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8096 KB Output is correct
2 Correct 0 ms 8096 KB Output is correct
3 Correct 0 ms 8096 KB Output is correct
4 Correct 0 ms 8096 KB Output is correct
5 Correct 0 ms 8096 KB Output is correct
6 Correct 0 ms 8096 KB Output is correct
7 Correct 0 ms 8096 KB Output is correct
8 Correct 0 ms 8096 KB Output is correct
9 Correct 0 ms 8096 KB Output is correct
10 Correct 0 ms 8096 KB Output is correct
11 Correct 0 ms 8228 KB Output is correct
12 Correct 0 ms 8096 KB Output is correct
13 Correct 0 ms 8096 KB Output is correct
14 Correct 0 ms 8228 KB Output is correct
15 Correct 0 ms 8228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8096 KB Output is correct
2 Correct 0 ms 8096 KB Output is correct
3 Correct 0 ms 8096 KB Output is correct
4 Correct 0 ms 8096 KB Output is correct
5 Correct 0 ms 8096 KB Output is correct
6 Correct 0 ms 8096 KB Output is correct
7 Correct 0 ms 8096 KB Output is correct
8 Correct 0 ms 8096 KB Output is correct
9 Correct 0 ms 8096 KB Output is correct
10 Correct 0 ms 8096 KB Output is correct
11 Correct 0 ms 8228 KB Output is correct
12 Correct 0 ms 8096 KB Output is correct
13 Correct 0 ms 8096 KB Output is correct
14 Correct 0 ms 8228 KB Output is correct
15 Correct 0 ms 8228 KB Output is correct
16 Correct 0 ms 8228 KB Output is correct
17 Correct 0 ms 8360 KB Output is correct
18 Correct 0 ms 8228 KB Output is correct
19 Correct 0 ms 8232 KB Output is correct
20 Correct 0 ms 8228 KB Output is correct
21 Correct 0 ms 8096 KB Output is correct
22 Correct 0 ms 8228 KB Output is correct
23 Correct 0 ms 8228 KB Output is correct
24 Correct 3 ms 8360 KB Output is correct
25 Correct 3 ms 8364 KB Output is correct
26 Correct 0 ms 8228 KB Output is correct
27 Correct 0 ms 8252 KB Output is correct
28 Correct 3 ms 8360 KB Output is correct
29 Correct 3 ms 9068 KB Output is correct
30 Correct 3 ms 8528 KB Output is correct
31 Correct 3 ms 8648 KB Output is correct
32 Correct 3 ms 8552 KB Output is correct
33 Correct 6 ms 9832 KB Output is correct
34 Correct 0 ms 9828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8096 KB Output is correct
2 Correct 0 ms 8096 KB Output is correct
3 Correct 0 ms 8096 KB Output is correct
4 Correct 0 ms 8096 KB Output is correct
5 Correct 0 ms 8096 KB Output is correct
6 Correct 0 ms 8096 KB Output is correct
7 Correct 0 ms 8096 KB Output is correct
8 Correct 0 ms 8096 KB Output is correct
9 Correct 0 ms 8096 KB Output is correct
10 Correct 0 ms 8096 KB Output is correct
11 Correct 0 ms 8228 KB Output is correct
12 Correct 0 ms 8096 KB Output is correct
13 Correct 0 ms 8096 KB Output is correct
14 Correct 0 ms 8228 KB Output is correct
15 Correct 0 ms 8228 KB Output is correct
16 Correct 0 ms 8228 KB Output is correct
17 Correct 0 ms 8360 KB Output is correct
18 Correct 0 ms 8228 KB Output is correct
19 Correct 0 ms 8232 KB Output is correct
20 Correct 3 ms 8228 KB Output is correct
21 Correct 0 ms 8096 KB Output is correct
22 Correct 0 ms 8228 KB Output is correct
23 Correct 0 ms 8228 KB Output is correct
24 Correct 3 ms 8360 KB Output is correct
25 Correct 3 ms 8364 KB Output is correct
26 Correct 0 ms 8228 KB Output is correct
27 Correct 0 ms 8252 KB Output is correct
28 Correct 3 ms 8360 KB Output is correct
29 Correct 3 ms 9068 KB Output is correct
30 Correct 0 ms 8528 KB Output is correct
31 Correct 3 ms 8648 KB Output is correct
32 Correct 3 ms 8552 KB Output is correct
33 Correct 3 ms 9832 KB Output is correct
34 Correct 3 ms 9828 KB Output is correct
35 Correct 9 ms 9944 KB Output is correct
36 Correct 0 ms 8496 KB Output is correct
37 Correct 13 ms 11044 KB Output is correct
38 Correct 16 ms 10868 KB Output is correct
39 Correct 13 ms 10896 KB Output is correct
40 Correct 19 ms 10868 KB Output is correct
41 Correct 9 ms 10868 KB Output is correct
42 Correct 9 ms 8228 KB Output is correct
43 Correct 6 ms 8252 KB Output is correct
44 Correct 0 ms 8228 KB Output is correct
45 Correct 16 ms 14576 KB Output is correct
46 Correct 16 ms 14604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8096 KB Output is correct
2 Correct 0 ms 8096 KB Output is correct
3 Correct 0 ms 8096 KB Output is correct
4 Correct 0 ms 8096 KB Output is correct
5 Correct 0 ms 8096 KB Output is correct
6 Correct 0 ms 8096 KB Output is correct
7 Correct 0 ms 8096 KB Output is correct
8 Correct 0 ms 8096 KB Output is correct
9 Correct 0 ms 8096 KB Output is correct
10 Correct 0 ms 8096 KB Output is correct
11 Correct 0 ms 8228 KB Output is correct
12 Correct 0 ms 8096 KB Output is correct
13 Correct 0 ms 8096 KB Output is correct
14 Correct 0 ms 8228 KB Output is correct
15 Correct 0 ms 8228 KB Output is correct
16 Correct 0 ms 8228 KB Output is correct
17 Correct 0 ms 8360 KB Output is correct
18 Correct 0 ms 8228 KB Output is correct
19 Correct 0 ms 8232 KB Output is correct
20 Correct 0 ms 8228 KB Output is correct
21 Correct 0 ms 8096 KB Output is correct
22 Correct 0 ms 8228 KB Output is correct
23 Correct 0 ms 8228 KB Output is correct
24 Correct 3 ms 8360 KB Output is correct
25 Correct 3 ms 8364 KB Output is correct
26 Correct 0 ms 8228 KB Output is correct
27 Correct 0 ms 8252 KB Output is correct
28 Correct 3 ms 8360 KB Output is correct
29 Correct 3 ms 9068 KB Output is correct
30 Correct 0 ms 8528 KB Output is correct
31 Correct 3 ms 8648 KB Output is correct
32 Correct 3 ms 8552 KB Output is correct
33 Correct 3 ms 9832 KB Output is correct
34 Correct 3 ms 9828 KB Output is correct
35 Correct 13 ms 9944 KB Output is correct
36 Correct 3 ms 8496 KB Output is correct
37 Correct 13 ms 11044 KB Output is correct
38 Correct 13 ms 10868 KB Output is correct
39 Correct 16 ms 10896 KB Output is correct
40 Correct 26 ms 10868 KB Output is correct
41 Correct 19 ms 10868 KB Output is correct
42 Correct 6 ms 8228 KB Output is correct
43 Correct 6 ms 8252 KB Output is correct
44 Correct 6 ms 8228 KB Output is correct
45 Correct 16 ms 14576 KB Output is correct
46 Correct 16 ms 14604 KB Output is correct
47 Correct 46 ms 18680 KB Output is correct
48 Correct 46 ms 11136 KB Output is correct
49 Correct 49 ms 10096 KB Output is correct
50 Correct 59 ms 10008 KB Output is correct
51 Correct 79 ms 13232 KB Output is correct
52 Correct 86 ms 13640 KB Output is correct
53 Correct 69 ms 10800 KB Output is correct
54 Correct 46 ms 8560 KB Output is correct
55 Correct 53 ms 9204 KB Output is correct
56 Correct 46 ms 9020 KB Output is correct
57 Correct 76 ms 17288 KB Output is correct
58 Correct 53 ms 9464 KB Output is correct
59 Correct 56 ms 9700 KB Output is correct
60 Correct 53 ms 10368 KB Output is correct
61 Correct 56 ms 9680 KB Output is correct
62 Correct 73 ms 14180 KB Output is correct
63 Correct 123 ms 36924 KB Output is correct
64 Correct 143 ms 50412 KB Output is correct
65 Correct 183 ms 65812 KB Output is correct
66 Correct 236 ms 100624 KB Output is correct
67 Correct 249 ms 99720 KB Output is correct