답안 #936550

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936550 2024-03-02T07:22:24 Z sleepntsheep Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
477 ms 79264 KB
#include<string.h>
#include<stdio.h>
#include<utility>
#include<queue>
#define N 30000
#define S 170
#define N1 2*(S*N+N+N)
int lo(int a,int b){return a<b?a:b;}
int z=1e9,n,m,b[N],p[N],e[N1][3],ne,h[N1],d[N1];

void link(int u,int v,int w) {e[++ne][0]=v,e[ne][1]=w,e[ne][2]=h[u],h[u]=ne;}

int bp(int bb,int pp){return bb+30000*pp+30000;}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;++i){
        scanf("%d%d",b+i,p+i);
        if(p[i]<S){
            link(b[i],bp(b[i],p[i]),0);
        }else{
            for(int dd=1,j=b[i]-p[i];j>=0;j-=p[i],++dd)link(b[i],j,dd);
            for(int dd=1,j=b[i]+p[i];j<n;j+=p[i],++dd)link(b[i],j,dd);
        }
    }

    memset(d,63,sizeof d);
    std::priority_queue<std::pair<int,int>>pq;
    pq.emplace(-(d[b[0]]=0),b[0]);
    while(pq.size())
    {
        auto[c,u]=pq.top();c=-c;pq.pop();
        if(d[u]-c)continue;
        for(int j=h[u];j;j=e[j][2])if(d[e[j][0]]>c+e[j][1])
            pq.emplace(-(d[e[j][0]]=c+e[j][1]),e[j][0]);
        if(u>=30000){
            int bb,pp;
            bb=(u-30000)%30000;
            pp=(u-30000)/30000;
            if(bb==b[1])z=lo(z,c);
            if(d[bb]>c)pq.emplace(-(d[bb]=c),bb);
            if(bb>=pp&&d[bp(bb-pp,pp)]>c+1)pq.emplace(-(d[bp(bb-pp,pp)]=c+1),bp(bb-pp,pp));
            if(bb+pp<n&&d[bp(bb+pp,pp)]>c+1)pq.emplace(-(d[bp(bb+pp,pp)]=c+1),bp(bb+pp,pp));
        } else if(u==b[1])z=lo(z,c);

    }

    if(z<1e9)printf("%d",z);else puts("-1");
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         scanf("%d%d",b+i,p+i);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 42844 KB Output is correct
2 Correct 6 ms 42844 KB Output is correct
3 Correct 5 ms 42844 KB Output is correct
4 Correct 6 ms 42844 KB Output is correct
5 Correct 6 ms 42844 KB Output is correct
6 Correct 6 ms 42844 KB Output is correct
7 Correct 6 ms 42708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 42840 KB Output is correct
2 Correct 6 ms 42840 KB Output is correct
3 Correct 6 ms 42844 KB Output is correct
4 Correct 6 ms 42844 KB Output is correct
5 Correct 6 ms 42844 KB Output is correct
6 Correct 6 ms 42844 KB Output is correct
7 Correct 6 ms 42844 KB Output is correct
8 Correct 7 ms 43096 KB Output is correct
9 Correct 6 ms 42844 KB Output is correct
10 Correct 6 ms 42844 KB Output is correct
11 Correct 6 ms 42844 KB Output is correct
12 Correct 6 ms 42844 KB Output is correct
13 Correct 7 ms 42800 KB Output is correct
14 Correct 7 ms 42716 KB Output is correct
15 Correct 7 ms 42840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 42844 KB Output is correct
2 Correct 6 ms 42880 KB Output is correct
3 Correct 6 ms 42844 KB Output is correct
4 Correct 6 ms 42844 KB Output is correct
5 Correct 6 ms 42840 KB Output is correct
6 Correct 6 ms 42840 KB Output is correct
7 Correct 5 ms 42844 KB Output is correct
8 Correct 6 ms 42724 KB Output is correct
9 Correct 6 ms 42840 KB Output is correct
10 Correct 6 ms 42844 KB Output is correct
11 Correct 6 ms 42844 KB Output is correct
12 Correct 7 ms 42844 KB Output is correct
13 Correct 6 ms 42772 KB Output is correct
14 Correct 7 ms 42844 KB Output is correct
15 Correct 7 ms 42844 KB Output is correct
16 Correct 6 ms 42844 KB Output is correct
17 Correct 7 ms 42840 KB Output is correct
18 Correct 6 ms 42748 KB Output is correct
19 Correct 6 ms 42844 KB Output is correct
20 Correct 6 ms 42748 KB Output is correct
21 Correct 6 ms 42844 KB Output is correct
22 Correct 6 ms 42844 KB Output is correct
23 Correct 7 ms 42844 KB Output is correct
24 Correct 7 ms 42844 KB Output is correct
25 Correct 6 ms 43096 KB Output is correct
26 Correct 7 ms 42840 KB Output is correct
27 Correct 6 ms 42840 KB Output is correct
28 Correct 7 ms 42784 KB Output is correct
29 Correct 10 ms 42912 KB Output is correct
30 Correct 7 ms 42844 KB Output is correct
31 Correct 9 ms 42844 KB Output is correct
32 Correct 8 ms 42844 KB Output is correct
33 Correct 15 ms 42844 KB Output is correct
34 Correct 15 ms 42844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 42840 KB Output is correct
2 Correct 5 ms 42844 KB Output is correct
3 Correct 6 ms 42844 KB Output is correct
4 Correct 6 ms 42844 KB Output is correct
5 Correct 6 ms 42844 KB Output is correct
6 Correct 6 ms 42844 KB Output is correct
7 Correct 6 ms 42844 KB Output is correct
8 Correct 6 ms 42844 KB Output is correct
9 Correct 6 ms 42844 KB Output is correct
10 Correct 6 ms 42844 KB Output is correct
11 Correct 7 ms 42844 KB Output is correct
12 Correct 6 ms 42844 KB Output is correct
13 Correct 6 ms 42840 KB Output is correct
14 Correct 7 ms 42748 KB Output is correct
15 Correct 6 ms 42844 KB Output is correct
16 Correct 6 ms 42844 KB Output is correct
17 Correct 7 ms 42844 KB Output is correct
18 Correct 6 ms 42844 KB Output is correct
19 Correct 6 ms 42768 KB Output is correct
20 Correct 6 ms 42844 KB Output is correct
21 Correct 6 ms 42720 KB Output is correct
22 Correct 6 ms 42844 KB Output is correct
23 Correct 7 ms 42844 KB Output is correct
24 Correct 7 ms 42844 KB Output is correct
25 Correct 6 ms 42844 KB Output is correct
26 Correct 7 ms 42844 KB Output is correct
27 Correct 7 ms 42844 KB Output is correct
28 Correct 7 ms 42844 KB Output is correct
29 Correct 10 ms 42844 KB Output is correct
30 Correct 7 ms 42844 KB Output is correct
31 Correct 8 ms 42744 KB Output is correct
32 Correct 7 ms 42844 KB Output is correct
33 Correct 16 ms 42744 KB Output is correct
34 Correct 16 ms 42844 KB Output is correct
35 Correct 16 ms 45148 KB Output is correct
36 Correct 8 ms 42844 KB Output is correct
37 Correct 20 ms 45148 KB Output is correct
38 Correct 20 ms 45404 KB Output is correct
39 Correct 23 ms 45380 KB Output is correct
40 Correct 20 ms 45404 KB Output is correct
41 Correct 20 ms 45660 KB Output is correct
42 Correct 10 ms 45104 KB Output is correct
43 Correct 10 ms 45148 KB Output is correct
44 Correct 10 ms 45144 KB Output is correct
45 Correct 41 ms 45404 KB Output is correct
46 Correct 41 ms 45400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 42844 KB Output is correct
2 Correct 6 ms 42732 KB Output is correct
3 Correct 6 ms 42844 KB Output is correct
4 Correct 6 ms 42748 KB Output is correct
5 Correct 6 ms 42844 KB Output is correct
6 Correct 6 ms 42844 KB Output is correct
7 Correct 7 ms 42840 KB Output is correct
8 Correct 6 ms 42840 KB Output is correct
9 Correct 6 ms 42844 KB Output is correct
10 Correct 6 ms 42720 KB Output is correct
11 Correct 7 ms 42844 KB Output is correct
12 Correct 6 ms 42844 KB Output is correct
13 Correct 6 ms 42844 KB Output is correct
14 Correct 7 ms 42728 KB Output is correct
15 Correct 6 ms 42844 KB Output is correct
16 Correct 6 ms 42844 KB Output is correct
17 Correct 7 ms 42972 KB Output is correct
18 Correct 6 ms 42660 KB Output is correct
19 Correct 6 ms 42844 KB Output is correct
20 Correct 6 ms 42844 KB Output is correct
21 Correct 6 ms 42844 KB Output is correct
22 Correct 7 ms 42844 KB Output is correct
23 Correct 7 ms 42940 KB Output is correct
24 Correct 8 ms 43252 KB Output is correct
25 Correct 7 ms 42752 KB Output is correct
26 Correct 7 ms 42844 KB Output is correct
27 Correct 6 ms 42844 KB Output is correct
28 Correct 7 ms 42840 KB Output is correct
29 Correct 10 ms 42844 KB Output is correct
30 Correct 7 ms 42844 KB Output is correct
31 Correct 8 ms 42844 KB Output is correct
32 Correct 8 ms 42844 KB Output is correct
33 Correct 18 ms 42968 KB Output is correct
34 Correct 16 ms 42964 KB Output is correct
35 Correct 18 ms 45148 KB Output is correct
36 Correct 9 ms 42844 KB Output is correct
37 Correct 20 ms 45148 KB Output is correct
38 Correct 21 ms 45424 KB Output is correct
39 Correct 20 ms 45284 KB Output is correct
40 Correct 19 ms 45420 KB Output is correct
41 Correct 21 ms 45404 KB Output is correct
42 Correct 10 ms 45300 KB Output is correct
43 Correct 10 ms 45112 KB Output is correct
44 Correct 10 ms 45148 KB Output is correct
45 Correct 42 ms 45364 KB Output is correct
46 Correct 40 ms 45400 KB Output is correct
47 Correct 59 ms 47704 KB Output is correct
48 Correct 10 ms 45148 KB Output is correct
49 Correct 9 ms 45148 KB Output is correct
50 Correct 8 ms 45148 KB Output is correct
51 Correct 32 ms 45720 KB Output is correct
52 Correct 36 ms 45660 KB Output is correct
53 Correct 12 ms 42844 KB Output is correct
54 Correct 6 ms 42844 KB Output is correct
55 Correct 8 ms 42996 KB Output is correct
56 Correct 11 ms 45192 KB Output is correct
57 Correct 43 ms 43096 KB Output is correct
58 Correct 11 ms 45148 KB Output is correct
59 Correct 12 ms 45148 KB Output is correct
60 Correct 15 ms 45400 KB Output is correct
61 Correct 14 ms 45656 KB Output is correct
62 Correct 18 ms 45352 KB Output is correct
63 Correct 41 ms 70492 KB Output is correct
64 Correct 43 ms 76500 KB Output is correct
65 Correct 150 ms 79264 KB Output is correct
66 Correct 473 ms 70864 KB Output is correct
67 Correct 477 ms 70860 KB Output is correct