답안 #161664

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161664 2019-11-03T14:18:42 Z nvmdava Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
951 ms 3808 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define N 30005
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007LL
 
priority_queue<pair<int, int> > pq;

vector<int> dog[N];
 
bool vis[N];
int dist[N];
int n;

void go(int v){
	vis[v] = 1;
	for(int& x : dog[v]){
		for(int i = v + x, a = 1; i < n; i += x, ++a){
			if(dist[i] > dist[v] + a){
				dist[i] = dist[v] + a;
				pq.push({-dist[i], i});
			}
		}
		for(int i = v - x, a = 1; i >= 0; i -= x, ++a){
			if(dist[i] > dist[v] + a){
				dist[i] = dist[v] + a;
				pq.push({-dist[i], i});
			}
		}
	}
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int m;
    cin>>n>>m;
    int b, p;
    int s, e;
    cin>>s>>p;
    dog[s].push_back(p);
    cin>>e>>p;
    dog[e].push_back(p);
    m -= 2;

    memset(dist, 0x3f, sizeof dist);

    while(m--){
    	cin>>b>>p;
    	dog[b].push_back(p);
    }

    pq.push({0, s});
    dist[s] = 0;

    while(!pq.empty()){
    	int a = pq.top().ss;
    	pq.pop();
    	if(a == e){
    		cout<<dist[e];
    		return 0;
    	}
    	if(!vis[a])
    		go(a);
    }

    cout<<-1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 2 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1148 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1272 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 4 ms 1272 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1140 KB Output is correct
4 Correct 12 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 4 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 9 ms 1144 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1272 KB Output is correct
13 Correct 4 ms 1144 KB Output is correct
14 Correct 3 ms 1272 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 3 ms 1272 KB Output is correct
18 Correct 3 ms 1272 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 7 ms 1232 KB Output is correct
21 Correct 3 ms 1272 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 3 ms 1144 KB Output is correct
24 Correct 4 ms 1272 KB Output is correct
25 Correct 3 ms 1276 KB Output is correct
26 Correct 4 ms 1272 KB Output is correct
27 Correct 3 ms 1264 KB Output is correct
28 Correct 3 ms 1272 KB Output is correct
29 Correct 4 ms 1272 KB Output is correct
30 Correct 4 ms 1272 KB Output is correct
31 Correct 4 ms 1272 KB Output is correct
32 Correct 3 ms 1272 KB Output is correct
33 Correct 4 ms 1388 KB Output is correct
34 Correct 4 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1116 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1148 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 4 ms 1144 KB Output is correct
15 Correct 3 ms 1272 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 4 ms 1272 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 7 ms 1272 KB Output is correct
21 Correct 3 ms 1144 KB Output is correct
22 Correct 3 ms 1272 KB Output is correct
23 Correct 3 ms 1320 KB Output is correct
24 Correct 4 ms 1272 KB Output is correct
25 Correct 3 ms 1272 KB Output is correct
26 Correct 3 ms 1144 KB Output is correct
27 Correct 3 ms 1272 KB Output is correct
28 Correct 3 ms 1272 KB Output is correct
29 Correct 4 ms 1272 KB Output is correct
30 Correct 4 ms 1272 KB Output is correct
31 Correct 4 ms 1272 KB Output is correct
32 Correct 3 ms 1272 KB Output is correct
33 Correct 4 ms 1272 KB Output is correct
34 Correct 4 ms 1404 KB Output is correct
35 Correct 11 ms 1656 KB Output is correct
36 Correct 4 ms 1232 KB Output is correct
37 Correct 9 ms 1660 KB Output is correct
38 Correct 12 ms 1784 KB Output is correct
39 Correct 10 ms 1656 KB Output is correct
40 Correct 11 ms 1784 KB Output is correct
41 Correct 12 ms 1784 KB Output is correct
42 Correct 8 ms 1656 KB Output is correct
43 Correct 8 ms 1572 KB Output is correct
44 Correct 64 ms 1656 KB Output is correct
45 Correct 11 ms 1656 KB Output is correct
46 Correct 10 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 2 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1148 KB Output is correct
8 Correct 3 ms 1148 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1272 KB Output is correct
13 Correct 3 ms 1148 KB Output is correct
14 Correct 3 ms 1144 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1260 KB Output is correct
17 Correct 4 ms 1272 KB Output is correct
18 Correct 3 ms 1272 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 7 ms 1272 KB Output is correct
21 Correct 3 ms 1144 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 3 ms 1272 KB Output is correct
24 Correct 4 ms 1244 KB Output is correct
25 Correct 4 ms 1276 KB Output is correct
26 Correct 3 ms 1272 KB Output is correct
27 Correct 4 ms 1272 KB Output is correct
28 Correct 4 ms 1272 KB Output is correct
29 Correct 4 ms 1272 KB Output is correct
30 Correct 4 ms 1276 KB Output is correct
31 Correct 4 ms 1272 KB Output is correct
32 Correct 3 ms 1272 KB Output is correct
33 Correct 4 ms 1400 KB Output is correct
34 Correct 4 ms 1400 KB Output is correct
35 Correct 10 ms 1656 KB Output is correct
36 Correct 4 ms 1272 KB Output is correct
37 Correct 8 ms 1656 KB Output is correct
38 Correct 11 ms 1784 KB Output is correct
39 Correct 11 ms 1656 KB Output is correct
40 Correct 11 ms 1784 KB Output is correct
41 Correct 11 ms 1784 KB Output is correct
42 Correct 22 ms 1656 KB Output is correct
43 Correct 8 ms 1656 KB Output is correct
44 Correct 62 ms 1656 KB Output is correct
45 Correct 10 ms 1656 KB Output is correct
46 Correct 10 ms 1656 KB Output is correct
47 Correct 13 ms 2420 KB Output is correct
48 Correct 11 ms 1912 KB Output is correct
49 Correct 10 ms 1912 KB Output is correct
50 Correct 8 ms 1656 KB Output is correct
51 Correct 22 ms 3184 KB Output is correct
52 Correct 23 ms 2676 KB Output is correct
53 Correct 14 ms 2296 KB Output is correct
54 Correct 4 ms 1400 KB Output is correct
55 Correct 5 ms 1400 KB Output is correct
56 Correct 890 ms 2808 KB Output is correct
57 Correct 6 ms 2468 KB Output is correct
58 Correct 951 ms 1756 KB Output is correct
59 Correct 13 ms 1784 KB Output is correct
60 Correct 11 ms 1784 KB Output is correct
61 Correct 11 ms 1912 KB Output is correct
62 Correct 18 ms 2424 KB Output is correct
63 Correct 33 ms 2800 KB Output is correct
64 Correct 30 ms 2800 KB Output is correct
65 Correct 33 ms 2800 KB Output is correct
66 Correct 45 ms 3692 KB Output is correct
67 Correct 36 ms 3808 KB Output is correct