Submission #17605

# Submission time Handle Problem Language Result Execution time Memory
17605 2016-01-02T14:23:36 Z dohyun0324 Jakarta Skyscrapers (APIO15_skyscraper) C++
57 / 100
1000 ms 75356 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;
                arr[val][pos]=1;
                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 0 ms 25988 KB Output is correct
13 Correct 1 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 2 ms 25988 KB Output is correct
24 Correct 0 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 8 ms 26768 KB Output is correct
30 Correct 4 ms 26120 KB Output is correct
31 Correct 3 ms 26380 KB Output is correct
32 Correct 5 ms 26124 KB Output is correct
33 Correct 23 ms 27544 KB Output is correct
34 Correct 15 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 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 0 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 13 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 23 ms 27544 KB Output is correct
34 Correct 18 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 5 ms 27700 KB Output is correct
38 Correct 6 ms 27020 KB Output is correct
39 Correct 0 ms 26252 KB Output is correct
40 Correct 13 ms 26252 KB Output is correct
41 Correct 10 ms 26636 KB Output is correct
42 Correct 5 ms 26120 KB Output is correct
43 Correct 6 ms 26120 KB Output is correct
44 Correct 7 ms 26120 KB Output is correct
45 Correct 118 ms 32316 KB Output is correct
46 Correct 84 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 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 2 ms 25988 KB Output is correct
15 Correct 1 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 1 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 3 ms 25988 KB Output is correct
29 Correct 13 ms 26768 KB Output is correct
30 Correct 0 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 14 ms 27544 KB Output is correct
35 Correct 7 ms 26992 KB Output is correct
36 Correct 0 ms 25988 KB Output is correct
37 Correct 13 ms 27700 KB Output is correct
38 Correct 11 ms 27020 KB Output is correct
39 Correct 10 ms 26252 KB Output is correct
40 Correct 11 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 0 ms 26120 KB Output is correct
45 Correct 116 ms 32316 KB Output is correct
46 Correct 80 ms 32316 KB Output is correct
47 Correct 20 ms 32480 KB Output is correct
48 Correct 0 ms 26384 KB Output is correct
49 Correct 0 ms 26384 KB Output is correct
50 Correct 0 ms 26252 KB Output is correct
51 Correct 29 ms 29656 KB Output is correct
52 Correct 24 ms 29660 KB Output is correct
53 Correct 13 ms 26776 KB Output is correct
54 Correct 0 ms 26120 KB Output is correct
55 Correct 3 ms 26120 KB Output is correct
56 Correct 14 ms 27312 KB Output is correct
57 Correct 5 ms 27600 KB Output is correct
58 Correct 16 ms 26892 KB Output is correct
59 Correct 15 ms 26252 KB Output is correct
60 Correct 14 ms 26256 KB Output is correct
61 Correct 16 ms 26268 KB Output is correct
62 Correct 43 ms 27056 KB Output is correct
63 Correct 600 ms 38520 KB Output is correct
64 Correct 767 ms 38480 KB Output is correct
65 Execution timed out 1000 ms 75356 KB Program timed out
66 Halted 0 ms 0 KB -