Submission #17604

# Submission time Handle Problem Language Result Execution time Memory
17604 2016-01-02T14:19:41 Z dohyun0324 Jakarta Skyscrapers (APIO15_skyscraper) C++
57 / 100
358 ms 262144 KB
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
using namespace std;
typedef pair<int,int> ppair;
vector<int>v[30010];
priority_queue<ppair, vector<ppair>, greater<ppair> >q;
int ch[30010],val,x,y,pos,n,m,t,en,arr[200][30010],d[30010];
int main()
{
    int i,j;
    scanf("%d %d",&n,&m);
    t=sqrt(n);
    for(i=1;i<=m;i++){
        scanf("%d %d",&x,&y); v[++x].push_back(y);
        if(i==1) pos=x;
        if(i==2) en=x;
    }
    for(i=1;i<=n;i++) d[i]=1e9; d[pos]=0; ch[pos]=1;
    while(1)
    {
        for(i=0;i<v[pos].size();i++)
        {
            val=v[pos][i];
            if(val<=t)
            {
                if(arr[val][pos]) continue;
                for(j=pos+val;j<=n;j+=val){
                    q.push(make_pair(d[pos]+(j-pos)/val,j));
                    arr[val][j]=1;
                }
                for(j=pos-val;j>=1;j-=val){
                    q.push(make_pair(d[pos]+(pos-j)/val,j));
                    arr[val][j]=1;
                }
            }
            else
            {
                for(j=pos+val;j<=n;j+=val) q.push(make_pair(d[pos]+(j-pos)/val,j));
                for(j=pos-val;j>=1;j-=val) q.push(make_pair(d[pos]+(pos-j)/val,j));
            }
        }
        while(q.size() && ch[q.top().second]) q.pop();
        if(q.size()==0) break;
        pos=q.top().second; d[pos]=q.top().first; ch[pos]=1;
        if(q.top().second==en) break;
    }
    if(d[en]==1e9) printf("-1");
    else printf("%d",d[en]);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 25988 KB Output is correct
2 Correct 0 ms 25988 KB Output is correct
3 Correct 0 ms 25988 KB Output is correct
4 Correct 0 ms 25988 KB Output is correct
5 Correct 0 ms 25988 KB Output is correct
6 Correct 0 ms 25988 KB Output is correct
7 Correct 0 ms 25988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 25988 KB Output is correct
2 Correct 0 ms 25988 KB Output is correct
3 Correct 0 ms 25988 KB Output is correct
4 Correct 0 ms 25988 KB Output is correct
5 Correct 0 ms 25988 KB Output is correct
6 Correct 0 ms 25988 KB Output is correct
7 Correct 0 ms 25988 KB Output is correct
8 Correct 0 ms 25988 KB Output is correct
9 Correct 0 ms 25988 KB Output is correct
10 Correct 0 ms 25988 KB Output is correct
11 Correct 0 ms 25988 KB Output is correct
12 Correct 0 ms 25988 KB Output is correct
13 Correct 0 ms 25988 KB Output is correct
14 Correct 0 ms 25988 KB Output is correct
15 Correct 0 ms 25988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 25988 KB Output is correct
2 Correct 0 ms 25988 KB Output is correct
3 Correct 0 ms 25988 KB Output is correct
4 Correct 0 ms 25988 KB Output is correct
5 Correct 0 ms 25988 KB Output is correct
6 Correct 0 ms 25988 KB Output is correct
7 Correct 0 ms 25988 KB Output is correct
8 Correct 0 ms 25988 KB Output is correct
9 Correct 0 ms 25988 KB Output is correct
10 Correct 0 ms 25988 KB Output is correct
11 Correct 0 ms 25988 KB Output is correct
12 Correct 1 ms 25988 KB Output is correct
13 Correct 0 ms 25988 KB Output is correct
14 Correct 2 ms 25988 KB Output is correct
15 Correct 0 ms 25988 KB Output is correct
16 Correct 0 ms 25988 KB Output is correct
17 Correct 0 ms 26140 KB Output is correct
18 Correct 0 ms 25988 KB Output is correct
19 Correct 0 ms 25988 KB Output is correct
20 Correct 0 ms 25988 KB Output is correct
21 Correct 0 ms 25988 KB Output is correct
22 Correct 0 ms 25988 KB Output is correct
23 Correct 0 ms 25988 KB Output is correct
24 Correct 3 ms 26156 KB Output is correct
25 Correct 0 ms 25988 KB Output is correct
26 Correct 0 ms 25988 KB Output is correct
27 Correct 0 ms 25988 KB Output is correct
28 Correct 0 ms 25988 KB Output is correct
29 Correct 14 ms 26768 KB Output is correct
30 Correct 4 ms 26120 KB Output is correct
31 Correct 7 ms 26380 KB Output is correct
32 Correct 5 ms 26124 KB Output is correct
33 Correct 27 ms 27544 KB Output is correct
34 Correct 18 ms 27544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 25988 KB Output is correct
2 Correct 0 ms 25988 KB Output is correct
3 Correct 0 ms 25988 KB Output is correct
4 Correct 0 ms 25988 KB Output is correct
5 Correct 0 ms 25988 KB Output is correct
6 Correct 0 ms 25988 KB Output is correct
7 Correct 0 ms 25988 KB Output is correct
8 Correct 0 ms 25988 KB Output is correct
9 Correct 1 ms 25988 KB Output is correct
10 Correct 0 ms 25988 KB Output is correct
11 Correct 0 ms 25988 KB Output is correct
12 Correct 0 ms 25988 KB Output is correct
13 Correct 0 ms 25988 KB Output is correct
14 Correct 0 ms 25988 KB Output is correct
15 Correct 2 ms 25988 KB Output is correct
16 Correct 0 ms 25988 KB Output is correct
17 Correct 2 ms 26140 KB Output is correct
18 Correct 0 ms 25988 KB Output is correct
19 Correct 0 ms 25988 KB Output is correct
20 Correct 0 ms 25988 KB Output is correct
21 Correct 0 ms 25988 KB Output is correct
22 Correct 0 ms 25988 KB Output is correct
23 Correct 0 ms 25988 KB Output is correct
24 Correct 3 ms 26156 KB Output is correct
25 Correct 1 ms 25988 KB Output is correct
26 Correct 1 ms 25988 KB Output is correct
27 Correct 0 ms 25988 KB Output is correct
28 Correct 0 ms 25988 KB Output is correct
29 Correct 9 ms 26768 KB Output is correct
30 Correct 4 ms 26120 KB Output is correct
31 Correct 5 ms 26380 KB Output is correct
32 Correct 3 ms 26124 KB Output is correct
33 Correct 23 ms 27544 KB Output is correct
34 Correct 14 ms 27544 KB Output is correct
35 Correct 15 ms 26992 KB Output is correct
36 Correct 0 ms 25988 KB Output is correct
37 Correct 7 ms 27700 KB Output is correct
38 Correct 9 ms 27020 KB Output is correct
39 Correct 0 ms 26252 KB Output is correct
40 Correct 8 ms 26252 KB Output is correct
41 Correct 13 ms 26636 KB Output is correct
42 Correct 0 ms 26120 KB Output is correct
43 Correct 0 ms 26120 KB Output is correct
44 Correct 8 ms 26120 KB Output is correct
45 Correct 130 ms 32316 KB Output is correct
46 Correct 83 ms 32316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 25988 KB Output is correct
2 Correct 0 ms 25988 KB Output is correct
3 Correct 0 ms 25988 KB Output is correct
4 Correct 0 ms 25988 KB Output is correct
5 Correct 0 ms 25988 KB Output is correct
6 Correct 0 ms 25988 KB Output is correct
7 Correct 0 ms 25988 KB Output is correct
8 Correct 0 ms 25988 KB Output is correct
9 Correct 1 ms 25988 KB Output is correct
10 Correct 0 ms 25988 KB Output is correct
11 Correct 0 ms 25988 KB Output is correct
12 Correct 0 ms 25988 KB Output is correct
13 Correct 0 ms 25988 KB Output is correct
14 Correct 0 ms 25988 KB Output is correct
15 Correct 0 ms 25988 KB Output is correct
16 Correct 1 ms 25988 KB Output is correct
17 Correct 2 ms 26140 KB Output is correct
18 Correct 0 ms 25988 KB Output is correct
19 Correct 0 ms 25988 KB Output is correct
20 Correct 0 ms 25988 KB Output is correct
21 Correct 0 ms 25988 KB Output is correct
22 Correct 0 ms 25988 KB Output is correct
23 Correct 2 ms 25988 KB Output is correct
24 Correct 1 ms 26156 KB Output is correct
25 Correct 0 ms 25988 KB Output is correct
26 Correct 0 ms 25988 KB Output is correct
27 Correct 2 ms 25988 KB Output is correct
28 Correct 0 ms 25988 KB Output is correct
29 Correct 10 ms 26768 KB Output is correct
30 Correct 4 ms 26120 KB Output is correct
31 Correct 7 ms 26380 KB Output is correct
32 Correct 2 ms 26124 KB Output is correct
33 Correct 24 ms 27544 KB Output is correct
34 Correct 14 ms 27544 KB Output is correct
35 Correct 10 ms 26992 KB Output is correct
36 Correct 3 ms 25988 KB Output is correct
37 Correct 5 ms 27700 KB Output is correct
38 Correct 15 ms 27020 KB Output is correct
39 Correct 7 ms 26252 KB Output is correct
40 Correct 8 ms 26252 KB Output is correct
41 Correct 13 ms 26636 KB Output is correct
42 Correct 9 ms 26120 KB Output is correct
43 Correct 8 ms 26120 KB Output is correct
44 Correct 0 ms 26120 KB Output is correct
45 Correct 121 ms 32316 KB Output is correct
46 Correct 82 ms 32316 KB Output is correct
47 Correct 18 ms 32480 KB Output is correct
48 Correct 8 ms 26384 KB Output is correct
49 Correct 3 ms 26384 KB Output is correct
50 Correct 6 ms 26252 KB Output is correct
51 Correct 24 ms 29656 KB Output is correct
52 Correct 33 ms 29660 KB Output is correct
53 Correct 9 ms 26776 KB Output is correct
54 Correct 0 ms 26120 KB Output is correct
55 Correct 4 ms 26120 KB Output is correct
56 Correct 15 ms 27312 KB Output is correct
57 Correct 5 ms 27600 KB Output is correct
58 Memory limit exceeded 358 ms 262144 KB Memory limit exceeded
59 Halted 0 ms 0 KB -