Submission #18888

# Submission time Handle Problem Language Result Execution time Memory
18888 2016-02-16T11:17:25 Z chan492811 Jakarta Skyscrapers (APIO15_skyscraper) C++
57 / 100
408 ms 17108 KB
#include <cstdio>
#include <queue>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

struct data{
    int to,dist;
};
struct cmp{
    bool operator()(data d1,data d2){
        return d1.dist>d2.dist;
    }
};
int n,m;
int dist[2010];
int graph[2010][2010];
data arr[30010];
bool visit[2010];

void dij(int a){
    int i,j,flag=1,now;
    data s;
    while(flag){
        flag=0; now=21e8;
        for(i=0;i<n;i++){
            if(!visit[i] && dist[i] && dist[i]<now) a=i,flag=1,now=dist[i];
        }
        if(!flag) break; visit[a]=1;
        for(i=0;i<n;i++){
            if(!graph[a][i]) continue;
            if(!dist[i] || dist[i]>dist[a]+graph[a][i]) dist[i]=dist[a]+graph[a][i];
        }
    }
}
int main(){
    int i,j;
    scanf("%d %d",&n,&m);
    for(i=0;i<m;i++) scanf("%d %d",&arr[i].to,&arr[i].dist),visit[arr[i].to]=1;
    for(i=0;i<m;i++){
        for(j=0;j<n;j++){
            if(!(abs(arr[i].to-j)%arr[i].dist)){
                if(!graph[arr[i].to][j]) graph[arr[i].to][j]=abs(arr[i].to-j)/arr[i].dist;
                else graph[arr[i].to][j]=min(graph[arr[i].to][j],abs(arr[i].to-j)/arr[i].dist);
            }
        }
    }
    memset(visit,0,sizeof(visit));
    dist[arr[0].to]=1;
    dij(0);
    if(!visit[arr[1].to]) printf("-1");
    else printf("%d",dist[arr[1].to]-1);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17108 KB Output is correct
2 Correct 0 ms 17108 KB Output is correct
3 Correct 0 ms 17108 KB Output is correct
4 Correct 0 ms 17108 KB Output is correct
5 Correct 0 ms 17108 KB Output is correct
6 Correct 0 ms 17108 KB Output is correct
7 Correct 0 ms 17108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17108 KB Output is correct
2 Correct 0 ms 17108 KB Output is correct
3 Correct 0 ms 17108 KB Output is correct
4 Correct 0 ms 17108 KB Output is correct
5 Correct 0 ms 17108 KB Output is correct
6 Correct 0 ms 17108 KB Output is correct
7 Correct 0 ms 17108 KB Output is correct
8 Correct 0 ms 17108 KB Output is correct
9 Correct 0 ms 17108 KB Output is correct
10 Correct 0 ms 17108 KB Output is correct
11 Correct 0 ms 17108 KB Output is correct
12 Correct 0 ms 17108 KB Output is correct
13 Correct 0 ms 17108 KB Output is correct
14 Correct 0 ms 17108 KB Output is correct
15 Correct 0 ms 17108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17108 KB Output is correct
2 Correct 0 ms 17108 KB Output is correct
3 Correct 0 ms 17108 KB Output is correct
4 Correct 0 ms 17108 KB Output is correct
5 Correct 0 ms 17108 KB Output is correct
6 Correct 0 ms 17108 KB Output is correct
7 Correct 0 ms 17108 KB Output is correct
8 Correct 0 ms 17108 KB Output is correct
9 Correct 0 ms 17108 KB Output is correct
10 Correct 0 ms 17108 KB Output is correct
11 Correct 2 ms 17108 KB Output is correct
12 Correct 0 ms 17108 KB Output is correct
13 Correct 2 ms 17108 KB Output is correct
14 Correct 0 ms 17108 KB Output is correct
15 Correct 2 ms 17108 KB Output is correct
16 Correct 2 ms 17108 KB Output is correct
17 Correct 13 ms 17108 KB Output is correct
18 Correct 13 ms 17108 KB Output is correct
19 Correct 9 ms 17108 KB Output is correct
20 Correct 41 ms 17108 KB Output is correct
21 Correct 4 ms 17108 KB Output is correct
22 Correct 10 ms 17108 KB Output is correct
23 Correct 24 ms 17108 KB Output is correct
24 Correct 37 ms 17108 KB Output is correct
25 Correct 30 ms 17108 KB Output is correct
26 Correct 45 ms 17108 KB Output is correct
27 Correct 40 ms 17108 KB Output is correct
28 Correct 42 ms 17108 KB Output is correct
29 Correct 22 ms 17108 KB Output is correct
30 Correct 15 ms 17108 KB Output is correct
31 Correct 21 ms 17108 KB Output is correct
32 Correct 19 ms 17108 KB Output is correct
33 Correct 40 ms 17108 KB Output is correct
34 Correct 39 ms 17108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17108 KB Output is correct
2 Correct 0 ms 17108 KB Output is correct
3 Correct 0 ms 17108 KB Output is correct
4 Correct 0 ms 17108 KB Output is correct
5 Correct 0 ms 17108 KB Output is correct
6 Correct 0 ms 17108 KB Output is correct
7 Correct 0 ms 17108 KB Output is correct
8 Correct 0 ms 17108 KB Output is correct
9 Correct 0 ms 17108 KB Output is correct
10 Correct 0 ms 17108 KB Output is correct
11 Correct 0 ms 17108 KB Output is correct
12 Correct 0 ms 17108 KB Output is correct
13 Correct 0 ms 17108 KB Output is correct
14 Correct 2 ms 17108 KB Output is correct
15 Correct 0 ms 17108 KB Output is correct
16 Correct 2 ms 17108 KB Output is correct
17 Correct 12 ms 17108 KB Output is correct
18 Correct 13 ms 17108 KB Output is correct
19 Correct 9 ms 17108 KB Output is correct
20 Correct 38 ms 17108 KB Output is correct
21 Correct 4 ms 17108 KB Output is correct
22 Correct 7 ms 17108 KB Output is correct
23 Correct 20 ms 17108 KB Output is correct
24 Correct 40 ms 17108 KB Output is correct
25 Correct 41 ms 17108 KB Output is correct
26 Correct 45 ms 17108 KB Output is correct
27 Correct 41 ms 17108 KB Output is correct
28 Correct 38 ms 17108 KB Output is correct
29 Correct 19 ms 17108 KB Output is correct
30 Correct 15 ms 17108 KB Output is correct
31 Correct 21 ms 17108 KB Output is correct
32 Correct 19 ms 17108 KB Output is correct
33 Correct 40 ms 17108 KB Output is correct
34 Correct 40 ms 17108 KB Output is correct
35 Correct 226 ms 17108 KB Output is correct
36 Correct 36 ms 17108 KB Output is correct
37 Correct 247 ms 17108 KB Output is correct
38 Correct 367 ms 17108 KB Output is correct
39 Correct 372 ms 17108 KB Output is correct
40 Correct 374 ms 17108 KB Output is correct
41 Correct 372 ms 17108 KB Output is correct
42 Correct 354 ms 17108 KB Output is correct
43 Correct 355 ms 17108 KB Output is correct
44 Correct 352 ms 17108 KB Output is correct
45 Correct 399 ms 17108 KB Output is correct
46 Correct 408 ms 17108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17108 KB Output is correct
2 Correct 0 ms 17108 KB Output is correct
3 Correct 0 ms 17108 KB Output is correct
4 Correct 0 ms 17108 KB Output is correct
5 Correct 0 ms 17108 KB Output is correct
6 Correct 0 ms 17108 KB Output is correct
7 Correct 0 ms 17108 KB Output is correct
8 Correct 0 ms 17108 KB Output is correct
9 Correct 0 ms 17108 KB Output is correct
10 Correct 0 ms 17108 KB Output is correct
11 Correct 0 ms 17108 KB Output is correct
12 Correct 0 ms 17108 KB Output is correct
13 Correct 0 ms 17108 KB Output is correct
14 Correct 2 ms 17108 KB Output is correct
15 Correct 0 ms 17108 KB Output is correct
16 Correct 0 ms 17108 KB Output is correct
17 Correct 8 ms 17108 KB Output is correct
18 Correct 12 ms 17108 KB Output is correct
19 Correct 9 ms 17108 KB Output is correct
20 Correct 41 ms 17108 KB Output is correct
21 Correct 4 ms 17108 KB Output is correct
22 Correct 6 ms 17108 KB Output is correct
23 Correct 24 ms 17108 KB Output is correct
24 Correct 40 ms 17108 KB Output is correct
25 Correct 37 ms 17108 KB Output is correct
26 Correct 41 ms 17108 KB Output is correct
27 Correct 44 ms 17108 KB Output is correct
28 Correct 38 ms 17108 KB Output is correct
29 Correct 22 ms 17108 KB Output is correct
30 Correct 11 ms 17108 KB Output is correct
31 Correct 16 ms 17108 KB Output is correct
32 Correct 19 ms 17108 KB Output is correct
33 Correct 40 ms 17108 KB Output is correct
34 Correct 39 ms 17108 KB Output is correct
35 Correct 220 ms 17108 KB Output is correct
36 Correct 37 ms 17108 KB Output is correct
37 Correct 256 ms 17108 KB Output is correct
38 Correct 364 ms 17108 KB Output is correct
39 Correct 370 ms 17108 KB Output is correct
40 Correct 369 ms 17108 KB Output is correct
41 Correct 366 ms 17108 KB Output is correct
42 Correct 356 ms 17108 KB Output is correct
43 Correct 360 ms 17108 KB Output is correct
44 Correct 352 ms 17108 KB Output is correct
45 Correct 405 ms 17108 KB Output is correct
46 Correct 404 ms 17108 KB Output is correct
47 Runtime error 0 ms 17104 KB SIGSEGV Segmentation fault
48 Halted 0 ms 0 KB -