답안 #27357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27357 2017-07-12T10:32:32 Z TAMREF Jakarta Skyscrapers (APIO15_skyscraper) C++11
57 / 100
1000 ms 5288 KB
#include <bits/stdc++.h>
#define va first
#define vb second
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
typedef pair<int,int> pii;
const int mx=30005;
int dist[mx];
pii doge[mx];
vector<int> C[mx];
int N,M;
void input(){
    scanf("%d%d",&N,&M);
    for(int i=0;i<M;i++){
        scanf("%d%d",&doge[i].va,&doge[i].vb);
        C[doge[i].va].push_back(doge[i].vb);
    }
    for(int i=0;i<N;i++){
        sort(all(C[i]),greater<int>());
        C[i].erase(unique(all(C[i])),C[i].end());
    }
    fill(dist,dist+N,(int)1e9);
}
void dijk(int s){
    priority_queue<pii,vector<pii>,greater<pii>> q;
    q.push(mp(dist[s]=0,s));
    pii t;
    while(!q.empty()){
        t=q.top(); q.pop();
        if(t.va>dist[t.vb]) continue;
        for(int p : C[t.vb]){
            for(int x=t.vb+p;x<N;x+=p){
                if(dist[x]>t.va+(x-t.vb)/p){
                    q.push(mp(dist[x]=t.va+(x-t.vb)/p,x));
                    if(binary_search(all(C[x]),p)) break;
                }
            }
            for(int x=t.vb-p;x>=0;x-=p){
                if(dist[x]>t.va+(t.vb-x)/p){
                    q.push(mp(dist[x]=t.va+(t.vb-x)/p,x));
                    if(binary_search(all(C[x]),p)) break;
                }
            }
        }
    }
}
int main(){
    input();
    dijk(doge[0].va);
    printf("%d\n",dist[doge[1].va]==(int)1e9?-1:dist[doge[1].va]);
}

Compilation message

skyscraper.cpp: In function 'void input()':
skyscraper.cpp:14:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&N,&M);
                        ^
skyscraper.cpp:16:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&doge[i].va,&doge[i].vb);
                                              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3076 KB Output is correct
2 Correct 0 ms 3076 KB Output is correct
3 Correct 0 ms 3076 KB Output is correct
4 Correct 0 ms 3076 KB Output is correct
5 Correct 0 ms 3076 KB Output is correct
6 Correct 0 ms 3076 KB Output is correct
7 Correct 0 ms 3076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3076 KB Output is correct
2 Correct 0 ms 3076 KB Output is correct
3 Correct 0 ms 3076 KB Output is correct
4 Correct 0 ms 3076 KB Output is correct
5 Correct 0 ms 3076 KB Output is correct
6 Correct 0 ms 3076 KB Output is correct
7 Correct 0 ms 3076 KB Output is correct
8 Correct 0 ms 3076 KB Output is correct
9 Correct 0 ms 3076 KB Output is correct
10 Correct 0 ms 3076 KB Output is correct
11 Correct 0 ms 3076 KB Output is correct
12 Correct 0 ms 3076 KB Output is correct
13 Correct 0 ms 3076 KB Output is correct
14 Correct 0 ms 3076 KB Output is correct
15 Correct 0 ms 3076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3076 KB Output is correct
2 Correct 0 ms 3076 KB Output is correct
3 Correct 0 ms 3076 KB Output is correct
4 Correct 0 ms 3076 KB Output is correct
5 Correct 0 ms 3076 KB Output is correct
6 Correct 0 ms 3076 KB Output is correct
7 Correct 0 ms 3076 KB Output is correct
8 Correct 0 ms 3076 KB Output is correct
9 Correct 0 ms 3076 KB Output is correct
10 Correct 0 ms 3076 KB Output is correct
11 Correct 0 ms 3076 KB Output is correct
12 Correct 0 ms 3076 KB Output is correct
13 Correct 0 ms 3076 KB Output is correct
14 Correct 0 ms 3076 KB Output is correct
15 Correct 0 ms 3076 KB Output is correct
16 Correct 0 ms 3076 KB Output is correct
17 Correct 0 ms 3208 KB Output is correct
18 Correct 0 ms 3076 KB Output is correct
19 Correct 0 ms 3076 KB Output is correct
20 Correct 6 ms 3208 KB Output is correct
21 Correct 0 ms 3076 KB Output is correct
22 Correct 0 ms 3076 KB Output is correct
23 Correct 0 ms 3076 KB Output is correct
24 Correct 0 ms 3220 KB Output is correct
25 Correct 0 ms 3208 KB Output is correct
26 Correct 0 ms 3076 KB Output is correct
27 Correct 0 ms 3076 KB Output is correct
28 Correct 0 ms 3208 KB Output is correct
29 Correct 0 ms 3224 KB Output is correct
30 Correct 0 ms 3220 KB Output is correct
31 Correct 0 ms 3220 KB Output is correct
32 Correct 0 ms 3224 KB Output is correct
33 Correct 0 ms 3232 KB Output is correct
34 Correct 3 ms 3232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3076 KB Output is correct
2 Correct 0 ms 3076 KB Output is correct
3 Correct 0 ms 3076 KB Output is correct
4 Correct 0 ms 3076 KB Output is correct
5 Correct 0 ms 3076 KB Output is correct
6 Correct 0 ms 3076 KB Output is correct
7 Correct 0 ms 3076 KB Output is correct
8 Correct 0 ms 3076 KB Output is correct
9 Correct 0 ms 3076 KB Output is correct
10 Correct 0 ms 3076 KB Output is correct
11 Correct 0 ms 3076 KB Output is correct
12 Correct 0 ms 3076 KB Output is correct
13 Correct 0 ms 3076 KB Output is correct
14 Correct 0 ms 3076 KB Output is correct
15 Correct 0 ms 3076 KB Output is correct
16 Correct 0 ms 3076 KB Output is correct
17 Correct 0 ms 3208 KB Output is correct
18 Correct 0 ms 3076 KB Output is correct
19 Correct 0 ms 3076 KB Output is correct
20 Correct 6 ms 3208 KB Output is correct
21 Correct 0 ms 3076 KB Output is correct
22 Correct 0 ms 3076 KB Output is correct
23 Correct 0 ms 3076 KB Output is correct
24 Correct 0 ms 3220 KB Output is correct
25 Correct 0 ms 3208 KB Output is correct
26 Correct 0 ms 3076 KB Output is correct
27 Correct 0 ms 3076 KB Output is correct
28 Correct 0 ms 3208 KB Output is correct
29 Correct 0 ms 3224 KB Output is correct
30 Correct 0 ms 3220 KB Output is correct
31 Correct 0 ms 3220 KB Output is correct
32 Correct 0 ms 3224 KB Output is correct
33 Correct 3 ms 3232 KB Output is correct
34 Correct 3 ms 3232 KB Output is correct
35 Correct 13 ms 3340 KB Output is correct
36 Correct 3 ms 3208 KB Output is correct
37 Correct 6 ms 3344 KB Output is correct
38 Correct 13 ms 3524 KB Output is correct
39 Correct 9 ms 3520 KB Output is correct
40 Correct 9 ms 3524 KB Output is correct
41 Correct 6 ms 3524 KB Output is correct
42 Correct 9 ms 3352 KB Output is correct
43 Correct 3 ms 3352 KB Output is correct
44 Correct 19 ms 3348 KB Output is correct
45 Correct 13 ms 3344 KB Output is correct
46 Correct 9 ms 3340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3076 KB Output is correct
2 Correct 0 ms 3076 KB Output is correct
3 Correct 0 ms 3076 KB Output is correct
4 Correct 0 ms 3076 KB Output is correct
5 Correct 0 ms 3076 KB Output is correct
6 Correct 0 ms 3076 KB Output is correct
7 Correct 0 ms 3076 KB Output is correct
8 Correct 0 ms 3076 KB Output is correct
9 Correct 0 ms 3076 KB Output is correct
10 Correct 0 ms 3076 KB Output is correct
11 Correct 0 ms 3076 KB Output is correct
12 Correct 0 ms 3076 KB Output is correct
13 Correct 0 ms 3076 KB Output is correct
14 Correct 0 ms 3076 KB Output is correct
15 Correct 0 ms 3076 KB Output is correct
16 Correct 0 ms 3076 KB Output is correct
17 Correct 0 ms 3208 KB Output is correct
18 Correct 0 ms 3076 KB Output is correct
19 Correct 0 ms 3076 KB Output is correct
20 Correct 9 ms 3208 KB Output is correct
21 Correct 0 ms 3076 KB Output is correct
22 Correct 0 ms 3076 KB Output is correct
23 Correct 0 ms 3076 KB Output is correct
24 Correct 0 ms 3220 KB Output is correct
25 Correct 0 ms 3208 KB Output is correct
26 Correct 0 ms 3076 KB Output is correct
27 Correct 0 ms 3076 KB Output is correct
28 Correct 0 ms 3208 KB Output is correct
29 Correct 0 ms 3224 KB Output is correct
30 Correct 0 ms 3220 KB Output is correct
31 Correct 0 ms 3220 KB Output is correct
32 Correct 0 ms 3224 KB Output is correct
33 Correct 0 ms 3232 KB Output is correct
34 Correct 0 ms 3232 KB Output is correct
35 Correct 9 ms 3340 KB Output is correct
36 Correct 0 ms 3208 KB Output is correct
37 Correct 3 ms 3344 KB Output is correct
38 Correct 13 ms 3524 KB Output is correct
39 Correct 9 ms 3520 KB Output is correct
40 Correct 16 ms 3524 KB Output is correct
41 Correct 9 ms 3524 KB Output is correct
42 Correct 9 ms 3352 KB Output is correct
43 Correct 6 ms 3352 KB Output is correct
44 Correct 9 ms 3348 KB Output is correct
45 Correct 9 ms 3344 KB Output is correct
46 Correct 6 ms 3340 KB Output is correct
47 Correct 33 ms 4272 KB Output is correct
48 Correct 9 ms 3604 KB Output is correct
49 Correct 9 ms 3604 KB Output is correct
50 Correct 6 ms 3472 KB Output is correct
51 Correct 43 ms 5288 KB Output is correct
52 Correct 36 ms 4524 KB Output is correct
53 Correct 19 ms 4524 KB Output is correct
54 Correct 0 ms 3348 KB Output is correct
55 Correct 3 ms 3348 KB Output is correct
56 Execution timed out 1000 ms 4000 KB Execution timed out
57 Halted 0 ms 0 KB -