Submission #14578

# Submission time Handle Problem Language Result Execution time Memory
14578 2015-05-20T07:04:50 Z dohyun0324 Jakarta Skyscrapers (APIO15_skyscraper) C++
100 / 100
399 ms 8604 KB
#include<stdio.h>
#include<math.h>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
bool ch[30010][175];
vector<int>con[30010];
typedef pair<int,int> ppair;
struct data{
    int val,x,y;
    char c;
    bool operator<(const data&r)const{
        return val>r.val;
    }
}b;
queue<data>q,imsi;
int sw,n,m,root,s,pos,f=-1,r=0;
struct data2{
    int x,p;
}a[30010];
int main()
{
    int sw2,i,j,val,x,y,c,w=0;
    scanf("%d %d",&n,&m);
    root=sqrt(n);
    for(i=0;i<m;i++){scanf("%d %d",&a[i].x,&a[i].p); con[a[i].x].push_back(a[i].p);}
    b.val=0, b.x=a[0].x, b.y=a[0].p, q.push(b);
    while(q.size()){
        sw2=0;
        while(q.size()){
            x=q.front().x; val=q.front().val; y=q.front().y; c=q.front().c;
            if(q.front().y<=root){
                if(ch[q.front().x][q.front().y]){
                    q.pop();
                    if(q.size()==0){
                        while(imsi.size()){q.push(imsi.front()); imsi.pop();}
                    }
                    continue;
                }
                else{sw2=1; break;}
            }
            if(x==a[1].x){printf("%d",val); return 0;}
            if(ch[x][0]==0){
                for(i=0;i<con[x].size();i++){
                    b.val=val; b.x=x; b.y=con[x][i]; b.c=0;
                    q.push(b);
                }
            }
            if(c==1 || c==0){
                for(i=x+y;i<n;i+=y){
                    b.val=val+1; b.x=i; b.y=y; b.c=1; imsi.push(b); break;
                }
            }
            if(c==2 || c==0){
                for(i=x-y;i>=0;i-=y){
                    b.val=val+1; b.x=i; b.y=y; b.c=2; imsi.push(b); break;
                }
            }
            ch[x][0]=1; q.pop();
            if(q.size()==0){
                while(imsi.size()){q.push(imsi.front()); imsi.pop();}
            }
        }
        if(!sw2){sw=1; break;}
        val=q.front().val; x=q.front().x; y=q.front().y; ch[x][y]=1;
        if(x==a[1].x) break;
        if(ch[x][0]==0){
            for(i=0;i<con[x].size();i++){
                b.val=val; b.x=x; b.y=con[x][i]; b.c=0;
                q.push(b);
            }
        }
        ch[x][0]=1;
        q.pop();
        if(x+y<n) b.val=val+1, b.x=x+y, b.y=y, b.c=0, imsi.push(b);
        if(x-y>=0) b.val=val+1, b.x=x-y, b.y=y, b.c=0, imsi.push(b);
        if(q.size()==0){
            while(imsi.size()){q.push(imsi.front()); imsi.pop();}
        }
    }
    if(sw) printf("-1");
    else printf("%d",val);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 7680 KB Output is correct
2 Correct 0 ms 7680 KB Output is correct
3 Correct 0 ms 7680 KB Output is correct
4 Correct 0 ms 7680 KB Output is correct
5 Correct 0 ms 7680 KB Output is correct
6 Correct 0 ms 7680 KB Output is correct
7 Correct 0 ms 7680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 7680 KB Output is correct
2 Correct 1 ms 7680 KB Output is correct
3 Correct 0 ms 7680 KB Output is correct
4 Correct 0 ms 7680 KB Output is correct
5 Correct 0 ms 7680 KB Output is correct
6 Correct 0 ms 7680 KB Output is correct
7 Correct 0 ms 7680 KB Output is correct
8 Correct 0 ms 7680 KB Output is correct
9 Correct 0 ms 7680 KB Output is correct
10 Correct 0 ms 7680 KB Output is correct
11 Correct 0 ms 7680 KB Output is correct
12 Correct 0 ms 7680 KB Output is correct
13 Correct 0 ms 7680 KB Output is correct
14 Correct 0 ms 7680 KB Output is correct
15 Correct 0 ms 7680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 7680 KB Output is correct
2 Correct 0 ms 7680 KB Output is correct
3 Correct 0 ms 7680 KB Output is correct
4 Correct 0 ms 7680 KB Output is correct
5 Correct 0 ms 7680 KB Output is correct
6 Correct 0 ms 7680 KB Output is correct
7 Correct 0 ms 7680 KB Output is correct
8 Correct 0 ms 7680 KB Output is correct
9 Correct 0 ms 7680 KB Output is correct
10 Correct 0 ms 7680 KB Output is correct
11 Correct 0 ms 7680 KB Output is correct
12 Correct 0 ms 7680 KB Output is correct
13 Correct 0 ms 7680 KB Output is correct
14 Correct 0 ms 7680 KB Output is correct
15 Correct 0 ms 7680 KB Output is correct
16 Correct 0 ms 7680 KB Output is correct
17 Correct 0 ms 7680 KB Output is correct
18 Correct 0 ms 7680 KB Output is correct
19 Correct 1 ms 7680 KB Output is correct
20 Correct 0 ms 7680 KB Output is correct
21 Correct 0 ms 7680 KB Output is correct
22 Correct 0 ms 7680 KB Output is correct
23 Correct 0 ms 7680 KB Output is correct
24 Correct 1 ms 7680 KB Output is correct
25 Correct 0 ms 7680 KB Output is correct
26 Correct 0 ms 7680 KB Output is correct
27 Correct 0 ms 7680 KB Output is correct
28 Correct 0 ms 7680 KB Output is correct
29 Correct 4 ms 7680 KB Output is correct
30 Correct 0 ms 7680 KB Output is correct
31 Correct 3 ms 7680 KB Output is correct
32 Correct 0 ms 7680 KB Output is correct
33 Correct 4 ms 7680 KB Output is correct
34 Correct 4 ms 7680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 7680 KB Output is correct
2 Correct 0 ms 7680 KB Output is correct
3 Correct 0 ms 7680 KB Output is correct
4 Correct 0 ms 7680 KB Output is correct
5 Correct 0 ms 7680 KB Output is correct
6 Correct 0 ms 7680 KB Output is correct
7 Correct 0 ms 7680 KB Output is correct
8 Correct 0 ms 7680 KB Output is correct
9 Correct 0 ms 7680 KB Output is correct
10 Correct 0 ms 7680 KB Output is correct
11 Correct 0 ms 7680 KB Output is correct
12 Correct 1 ms 7680 KB Output is correct
13 Correct 0 ms 7680 KB Output is correct
14 Correct 0 ms 7680 KB Output is correct
15 Correct 0 ms 7680 KB Output is correct
16 Correct 0 ms 7680 KB Output is correct
17 Correct 0 ms 7680 KB Output is correct
18 Correct 0 ms 7680 KB Output is correct
19 Correct 0 ms 7680 KB Output is correct
20 Correct 0 ms 7680 KB Output is correct
21 Correct 1 ms 7680 KB Output is correct
22 Correct 0 ms 7680 KB Output is correct
23 Correct 0 ms 7680 KB Output is correct
24 Correct 0 ms 7680 KB Output is correct
25 Correct 0 ms 7680 KB Output is correct
26 Correct 0 ms 7680 KB Output is correct
27 Correct 0 ms 7680 KB Output is correct
28 Correct 0 ms 7680 KB Output is correct
29 Correct 2 ms 7680 KB Output is correct
30 Correct 0 ms 7680 KB Output is correct
31 Correct 0 ms 7680 KB Output is correct
32 Correct 0 ms 7680 KB Output is correct
33 Correct 7 ms 7680 KB Output is correct
34 Correct 4 ms 7680 KB Output is correct
35 Correct 12 ms 8076 KB Output is correct
36 Correct 2 ms 7680 KB Output is correct
37 Correct 7 ms 7944 KB Output is correct
38 Correct 4 ms 8208 KB Output is correct
39 Correct 0 ms 7812 KB Output is correct
40 Correct 0 ms 7812 KB Output is correct
41 Correct 0 ms 7944 KB Output is correct
42 Correct 0 ms 7812 KB Output is correct
43 Correct 0 ms 7812 KB Output is correct
44 Correct 0 ms 8344 KB Output is correct
45 Correct 21 ms 8340 KB Output is correct
46 Correct 14 ms 8340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 7680 KB Output is correct
2 Correct 0 ms 7680 KB Output is correct
3 Correct 0 ms 7680 KB Output is correct
4 Correct 0 ms 7680 KB Output is correct
5 Correct 0 ms 7680 KB Output is correct
6 Correct 0 ms 7680 KB Output is correct
7 Correct 0 ms 7680 KB Output is correct
8 Correct 0 ms 7680 KB Output is correct
9 Correct 0 ms 7680 KB Output is correct
10 Correct 0 ms 7680 KB Output is correct
11 Correct 0 ms 7680 KB Output is correct
12 Correct 0 ms 7680 KB Output is correct
13 Correct 0 ms 7680 KB Output is correct
14 Correct 0 ms 7680 KB Output is correct
15 Correct 0 ms 7680 KB Output is correct
16 Correct 0 ms 7680 KB Output is correct
17 Correct 0 ms 7680 KB Output is correct
18 Correct 0 ms 7680 KB Output is correct
19 Correct 0 ms 7680 KB Output is correct
20 Correct 0 ms 7680 KB Output is correct
21 Correct 0 ms 7680 KB Output is correct
22 Correct 0 ms 7680 KB Output is correct
23 Correct 2 ms 7680 KB Output is correct
24 Correct 2 ms 7680 KB Output is correct
25 Correct 0 ms 7680 KB Output is correct
26 Correct 0 ms 7680 KB Output is correct
27 Correct 0 ms 7680 KB Output is correct
28 Correct 3 ms 7680 KB Output is correct
29 Correct 4 ms 7680 KB Output is correct
30 Correct 2 ms 7680 KB Output is correct
31 Correct 3 ms 7680 KB Output is correct
32 Correct 0 ms 7680 KB Output is correct
33 Correct 7 ms 7680 KB Output is correct
34 Correct 4 ms 7680 KB Output is correct
35 Correct 6 ms 8076 KB Output is correct
36 Correct 1 ms 7680 KB Output is correct
37 Correct 3 ms 7944 KB Output is correct
38 Correct 10 ms 8208 KB Output is correct
39 Correct 10 ms 7812 KB Output is correct
40 Correct 5 ms 7812 KB Output is correct
41 Correct 12 ms 7944 KB Output is correct
42 Correct 6 ms 7812 KB Output is correct
43 Correct 7 ms 7812 KB Output is correct
44 Correct 5 ms 8344 KB Output is correct
45 Correct 22 ms 8340 KB Output is correct
46 Correct 11 ms 8340 KB Output is correct
47 Correct 10 ms 8076 KB Output is correct
48 Correct 11 ms 8076 KB Output is correct
49 Correct 8 ms 8076 KB Output is correct
50 Correct 0 ms 7944 KB Output is correct
51 Correct 14 ms 8340 KB Output is correct
52 Correct 13 ms 8340 KB Output is correct
53 Correct 5 ms 8208 KB Output is correct
54 Correct 3 ms 7680 KB Output is correct
55 Correct 4 ms 7680 KB Output is correct
56 Correct 14 ms 8604 KB Output is correct
57 Correct 0 ms 7680 KB Output is correct
58 Correct 11 ms 8208 KB Output is correct
59 Correct 12 ms 7812 KB Output is correct
60 Correct 11 ms 7816 KB Output is correct
61 Correct 8 ms 7828 KB Output is correct
62 Correct 42 ms 8604 KB Output is correct
63 Correct 63 ms 8204 KB Output is correct
64 Correct 89 ms 8076 KB Output is correct
65 Correct 165 ms 8336 KB Output is correct
66 Correct 399 ms 8604 KB Output is correct
67 Correct 182 ms 8604 KB Output is correct