답안 #18884

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
18884 2016-02-16T10:51:20 Z chan492811 Jakarta Skyscrapers (APIO15_skyscraper) C++
36 / 100
1000 ms 34868 KB
#include <cstdio>
#include <queue>
#include <vector>
#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[30010];
data arr[30010];
bool visit[30010];
vector<data> vt[30010];
priority_queue<data,vector<data>,cmp> pq;

void dij(int a){
    int i;
    data s;
    pq.push((data){a,1});
    while(!pq.empty()){
        a=pq.top().to; pq.pop();
        if(visit[a]) continue; visit[a]=1;
        for(i=0;i<vt[a].size();i++){
            s=vt[a][i];
            if(dist[s.to]==0 || dist[s.to]>dist[a]+s.dist){
                pq.push((data){s.to,dist[a]+s.dist}); dist[s.to]=dist[a]+s.dist;
            }
        }
    }
}
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);
    for(i=0;i<m;i++){
        for(j=i+1;j<m;j++){
            if(!(abs(arr[i].to-arr[j].to)%arr[i].dist)) vt[i].push_back((data){j,abs(arr[i].to-arr[j].to)/arr[i].dist});
            if(!(abs(arr[i].to-arr[j].to)%arr[j].dist)) vt[j].push_back((data){i,abs(arr[i].to-arr[j].to)/arr[j].dist});
        }
    }
    dist[0]=1;
    dij(0);
    if(!visit[1]) printf("-1");
    else printf("%d",dist[1]-1);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2664 KB Output is correct
2 Correct 0 ms 2664 KB Output is correct
3 Correct 0 ms 2664 KB Output is correct
4 Correct 0 ms 2664 KB Output is correct
5 Correct 0 ms 2664 KB Output is correct
6 Correct 0 ms 2664 KB Output is correct
7 Correct 0 ms 2664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2664 KB Output is correct
2 Correct 0 ms 2664 KB Output is correct
3 Correct 0 ms 2664 KB Output is correct
4 Correct 0 ms 2664 KB Output is correct
5 Correct 0 ms 2664 KB Output is correct
6 Correct 0 ms 2664 KB Output is correct
7 Correct 0 ms 2664 KB Output is correct
8 Correct 0 ms 2664 KB Output is correct
9 Correct 0 ms 2664 KB Output is correct
10 Correct 2 ms 2664 KB Output is correct
11 Correct 33 ms 4932 KB Output is correct
12 Correct 90 ms 34692 KB Output is correct
13 Correct 137 ms 34868 KB Output is correct
14 Correct 36 ms 4276 KB Output is correct
15 Correct 31 ms 4268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2664 KB Output is correct
2 Correct 0 ms 2664 KB Output is correct
3 Correct 0 ms 2664 KB Output is correct
4 Correct 0 ms 2664 KB Output is correct
5 Correct 0 ms 2664 KB Output is correct
6 Correct 0 ms 2664 KB Output is correct
7 Correct 0 ms 2664 KB Output is correct
8 Correct 0 ms 2664 KB Output is correct
9 Correct 0 ms 2664 KB Output is correct
10 Correct 0 ms 2664 KB Output is correct
11 Correct 38 ms 4932 KB Output is correct
12 Correct 97 ms 34692 KB Output is correct
13 Correct 106 ms 34868 KB Output is correct
14 Correct 36 ms 4276 KB Output is correct
15 Correct 33 ms 4268 KB Output is correct
16 Correct 7 ms 2932 KB Output is correct
17 Correct 24 ms 3352 KB Output is correct
18 Correct 6 ms 2664 KB Output is correct
19 Correct 1 ms 2664 KB Output is correct
20 Correct 92 ms 34868 KB Output is correct
21 Correct 8 ms 2664 KB Output is correct
22 Correct 4 ms 2664 KB Output is correct
23 Correct 6 ms 2664 KB Output is correct
24 Correct 23 ms 2796 KB Output is correct
25 Correct 23 ms 2796 KB Output is correct
26 Correct 120 ms 31716 KB Output is correct
27 Correct 126 ms 32712 KB Output is correct
28 Correct 25 ms 2796 KB Output is correct
29 Correct 4 ms 2928 KB Output is correct
30 Correct 0 ms 2664 KB Output is correct
31 Correct 3 ms 2796 KB Output is correct
32 Correct 0 ms 2664 KB Output is correct
33 Correct 36 ms 4276 KB Output is correct
34 Correct 28 ms 4268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2664 KB Output is correct
2 Correct 0 ms 2664 KB Output is correct
3 Correct 0 ms 2664 KB Output is correct
4 Correct 0 ms 2664 KB Output is correct
5 Correct 0 ms 2664 KB Output is correct
6 Correct 0 ms 2664 KB Output is correct
7 Correct 0 ms 2664 KB Output is correct
8 Correct 0 ms 2664 KB Output is correct
9 Correct 0 ms 2664 KB Output is correct
10 Correct 0 ms 2664 KB Output is correct
11 Correct 39 ms 4932 KB Output is correct
12 Correct 117 ms 34692 KB Output is correct
13 Correct 81 ms 34868 KB Output is correct
14 Correct 28 ms 4276 KB Output is correct
15 Correct 34 ms 4268 KB Output is correct
16 Correct 5 ms 2932 KB Output is correct
17 Correct 24 ms 3352 KB Output is correct
18 Correct 7 ms 2664 KB Output is correct
19 Correct 0 ms 2664 KB Output is correct
20 Correct 133 ms 34868 KB Output is correct
21 Correct 6 ms 2664 KB Output is correct
22 Correct 0 ms 2664 KB Output is correct
23 Correct 3 ms 2664 KB Output is correct
24 Correct 23 ms 2796 KB Output is correct
25 Correct 24 ms 2796 KB Output is correct
26 Correct 87 ms 31716 KB Output is correct
27 Correct 84 ms 32712 KB Output is correct
28 Correct 25 ms 2796 KB Output is correct
29 Correct 5 ms 2928 KB Output is correct
30 Correct 0 ms 2664 KB Output is correct
31 Correct 0 ms 2796 KB Output is correct
32 Correct 2 ms 2664 KB Output is correct
33 Correct 34 ms 4276 KB Output is correct
34 Correct 36 ms 4268 KB Output is correct
35 Execution timed out 1000 ms 19704 KB Program timed out
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2664 KB Output is correct
2 Correct 0 ms 2664 KB Output is correct
3 Correct 0 ms 2664 KB Output is correct
4 Correct 0 ms 2664 KB Output is correct
5 Correct 0 ms 2664 KB Output is correct
6 Correct 0 ms 2664 KB Output is correct
7 Correct 0 ms 2664 KB Output is correct
8 Correct 0 ms 2664 KB Output is correct
9 Correct 0 ms 2664 KB Output is correct
10 Correct 2 ms 2664 KB Output is correct
11 Correct 38 ms 4932 KB Output is correct
12 Correct 126 ms 34692 KB Output is correct
13 Correct 123 ms 34868 KB Output is correct
14 Correct 32 ms 4276 KB Output is correct
15 Correct 31 ms 4268 KB Output is correct
16 Correct 6 ms 2932 KB Output is correct
17 Correct 24 ms 3352 KB Output is correct
18 Correct 3 ms 2664 KB Output is correct
19 Correct 0 ms 2664 KB Output is correct
20 Correct 129 ms 34868 KB Output is correct
21 Correct 8 ms 2664 KB Output is correct
22 Correct 4 ms 2664 KB Output is correct
23 Correct 7 ms 2664 KB Output is correct
24 Correct 23 ms 2796 KB Output is correct
25 Correct 21 ms 2796 KB Output is correct
26 Correct 104 ms 31716 KB Output is correct
27 Correct 97 ms 32712 KB Output is correct
28 Correct 25 ms 2796 KB Output is correct
29 Correct 4 ms 2928 KB Output is correct
30 Correct 0 ms 2664 KB Output is correct
31 Correct 3 ms 2796 KB Output is correct
32 Correct 2 ms 2664 KB Output is correct
33 Correct 31 ms 4276 KB Output is correct
34 Correct 30 ms 4268 KB Output is correct
35 Execution timed out 1000 ms 19704 KB Program timed out
36 Halted 0 ms 0 KB -