답안 #41607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41607 2018-02-19T19:30:10 Z MatheusLealV Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
288 ms 67304 KB
#include <bits/stdc++.h>
#define N 30050
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;

int n, m, casa[N], len[N], dist[N];

unordered_set<int> pos[N];

vector<pii> grafo[N];

priority_queue<pii, vector<pii>, greater<pii> > pq;

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);

	cin>>m>>n;

	for(int i = 1; i <= n; i++)
	{
		cin>>casa[i]>>len[i];

		pos[ casa[i] ].insert( len[i] );
	}

	for(int i = 0; i < m; i++)
	{
		for(auto x: pos[i])
		{
			for(int j = i + x; j < m; j += x)
			{
				grafo[i].push_back({j, (j - i)/x});

				if(pos[j].count(x)) break;
			}

			for(int j = i - x; j >= 0; j -= x)
			{
				grafo[i].push_back({j, (i - j)/x});

				if(pos[j].count(x)) break;
			}
		}
	}

	for(int i = 0; i < m; i++) dist[i] = 2000000000;

	dist[ casa[1] ] = 0;

	pq.push({0, casa[1]});

	while(!pq.empty())
	{
		int x = pq.top().s, d = pq.top().f;

		pq.pop();

		if(d > dist[x]) continue;

		for(auto v: grafo[x])
		{
			if(dist[v.f] > dist[x] + v.s)
			{
				dist[v.f] = dist[x] + v.s;

				pq.push({dist[v.f], v.f});
			}
		}
	}

	cout<<(dist[casa[2]] != 2000000000 ? dist[casa[2]] : -1)<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2684 KB Output is correct
2 Correct 3 ms 2684 KB Output is correct
3 Correct 3 ms 2836 KB Output is correct
4 Correct 3 ms 2912 KB Output is correct
5 Correct 3 ms 2912 KB Output is correct
6 Correct 3 ms 2912 KB Output is correct
7 Correct 3 ms 2912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2912 KB Output is correct
2 Correct 4 ms 2912 KB Output is correct
3 Correct 3 ms 2912 KB Output is correct
4 Correct 3 ms 2912 KB Output is correct
5 Correct 3 ms 2912 KB Output is correct
6 Correct 4 ms 2912 KB Output is correct
7 Correct 4 ms 3036 KB Output is correct
8 Correct 3 ms 3036 KB Output is correct
9 Correct 3 ms 3036 KB Output is correct
10 Correct 4 ms 3036 KB Output is correct
11 Correct 4 ms 3052 KB Output is correct
12 Correct 5 ms 3052 KB Output is correct
13 Correct 5 ms 3052 KB Output is correct
14 Correct 6 ms 3052 KB Output is correct
15 Correct 4 ms 3052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3052 KB Output is correct
2 Correct 3 ms 3052 KB Output is correct
3 Correct 3 ms 3052 KB Output is correct
4 Correct 3 ms 3052 KB Output is correct
5 Correct 3 ms 3052 KB Output is correct
6 Correct 3 ms 3052 KB Output is correct
7 Correct 3 ms 3052 KB Output is correct
8 Correct 4 ms 3052 KB Output is correct
9 Correct 3 ms 3052 KB Output is correct
10 Correct 4 ms 3052 KB Output is correct
11 Correct 4 ms 3052 KB Output is correct
12 Correct 3 ms 3052 KB Output is correct
13 Correct 4 ms 3052 KB Output is correct
14 Correct 4 ms 3052 KB Output is correct
15 Correct 4 ms 3052 KB Output is correct
16 Correct 4 ms 3052 KB Output is correct
17 Correct 6 ms 3180 KB Output is correct
18 Correct 4 ms 3180 KB Output is correct
19 Correct 4 ms 3180 KB Output is correct
20 Correct 4 ms 3180 KB Output is correct
21 Correct 4 ms 3180 KB Output is correct
22 Correct 4 ms 3180 KB Output is correct
23 Correct 4 ms 3180 KB Output is correct
24 Correct 6 ms 3180 KB Output is correct
25 Correct 6 ms 3180 KB Output is correct
26 Correct 5 ms 3180 KB Output is correct
27 Correct 5 ms 3180 KB Output is correct
28 Correct 7 ms 3308 KB Output is correct
29 Correct 7 ms 3868 KB Output is correct
30 Correct 5 ms 3868 KB Output is correct
31 Correct 6 ms 3868 KB Output is correct
32 Correct 5 ms 3868 KB Output is correct
33 Correct 9 ms 4332 KB Output is correct
34 Correct 10 ms 4368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4368 KB Output is correct
2 Correct 3 ms 4368 KB Output is correct
3 Correct 3 ms 4368 KB Output is correct
4 Correct 3 ms 4368 KB Output is correct
5 Correct 3 ms 4368 KB Output is correct
6 Correct 4 ms 4368 KB Output is correct
7 Correct 4 ms 4368 KB Output is correct
8 Correct 4 ms 4368 KB Output is correct
9 Correct 4 ms 4368 KB Output is correct
10 Correct 4 ms 4368 KB Output is correct
11 Correct 5 ms 4368 KB Output is correct
12 Correct 3 ms 4368 KB Output is correct
13 Correct 4 ms 4368 KB Output is correct
14 Correct 4 ms 4368 KB Output is correct
15 Correct 4 ms 4368 KB Output is correct
16 Correct 4 ms 4368 KB Output is correct
17 Correct 6 ms 4368 KB Output is correct
18 Correct 4 ms 4368 KB Output is correct
19 Correct 5 ms 4368 KB Output is correct
20 Correct 4 ms 4368 KB Output is correct
21 Correct 4 ms 4368 KB Output is correct
22 Correct 4 ms 4368 KB Output is correct
23 Correct 4 ms 4368 KB Output is correct
24 Correct 6 ms 4368 KB Output is correct
25 Correct 7 ms 4368 KB Output is correct
26 Correct 4 ms 4368 KB Output is correct
27 Correct 5 ms 4368 KB Output is correct
28 Correct 7 ms 4368 KB Output is correct
29 Correct 9 ms 4368 KB Output is correct
30 Correct 6 ms 4368 KB Output is correct
31 Correct 7 ms 4368 KB Output is correct
32 Correct 5 ms 4368 KB Output is correct
33 Correct 9 ms 4368 KB Output is correct
34 Correct 9 ms 4368 KB Output is correct
35 Correct 35 ms 5372 KB Output is correct
36 Correct 9 ms 5372 KB Output is correct
37 Correct 29 ms 6124 KB Output is correct
38 Correct 31 ms 6252 KB Output is correct
39 Correct 31 ms 6380 KB Output is correct
40 Correct 32 ms 6380 KB Output is correct
41 Correct 33 ms 6380 KB Output is correct
42 Correct 9 ms 6380 KB Output is correct
43 Correct 9 ms 6380 KB Output is correct
44 Correct 12 ms 6380 KB Output is correct
45 Correct 32 ms 8880 KB Output is correct
46 Correct 30 ms 8940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8940 KB Output is correct
2 Correct 4 ms 8940 KB Output is correct
3 Correct 3 ms 8940 KB Output is correct
4 Correct 4 ms 8940 KB Output is correct
5 Correct 3 ms 8940 KB Output is correct
6 Correct 4 ms 8940 KB Output is correct
7 Correct 3 ms 8940 KB Output is correct
8 Correct 3 ms 8940 KB Output is correct
9 Correct 4 ms 8940 KB Output is correct
10 Correct 4 ms 8940 KB Output is correct
11 Correct 5 ms 8940 KB Output is correct
12 Correct 5 ms 8940 KB Output is correct
13 Correct 4 ms 8940 KB Output is correct
14 Correct 5 ms 8940 KB Output is correct
15 Correct 4 ms 8940 KB Output is correct
16 Correct 4 ms 8940 KB Output is correct
17 Correct 6 ms 8940 KB Output is correct
18 Correct 4 ms 8940 KB Output is correct
19 Correct 4 ms 8940 KB Output is correct
20 Correct 5 ms 8940 KB Output is correct
21 Correct 4 ms 8940 KB Output is correct
22 Correct 4 ms 8940 KB Output is correct
23 Correct 4 ms 8940 KB Output is correct
24 Correct 5 ms 8940 KB Output is correct
25 Correct 6 ms 8940 KB Output is correct
26 Correct 4 ms 8940 KB Output is correct
27 Correct 4 ms 8940 KB Output is correct
28 Correct 6 ms 8940 KB Output is correct
29 Correct 7 ms 8940 KB Output is correct
30 Correct 5 ms 8940 KB Output is correct
31 Correct 5 ms 8940 KB Output is correct
32 Correct 5 ms 8940 KB Output is correct
33 Correct 10 ms 8940 KB Output is correct
34 Correct 10 ms 8940 KB Output is correct
35 Correct 25 ms 8940 KB Output is correct
36 Correct 7 ms 8940 KB Output is correct
37 Correct 31 ms 8940 KB Output is correct
38 Correct 31 ms 8940 KB Output is correct
39 Correct 35 ms 8940 KB Output is correct
40 Correct 31 ms 8940 KB Output is correct
41 Correct 31 ms 8940 KB Output is correct
42 Correct 10 ms 8940 KB Output is correct
43 Correct 9 ms 8940 KB Output is correct
44 Correct 10 ms 8940 KB Output is correct
45 Correct 38 ms 8940 KB Output is correct
46 Correct 33 ms 8940 KB Output is correct
47 Correct 77 ms 13532 KB Output is correct
48 Correct 35 ms 13532 KB Output is correct
49 Correct 23 ms 13532 KB Output is correct
50 Correct 24 ms 13532 KB Output is correct
51 Correct 73 ms 13532 KB Output is correct
52 Correct 68 ms 13532 KB Output is correct
53 Correct 44 ms 13532 KB Output is correct
54 Correct 6 ms 13532 KB Output is correct
55 Correct 8 ms 13532 KB Output is correct
56 Correct 27 ms 13532 KB Output is correct
57 Correct 60 ms 13564 KB Output is correct
58 Correct 14 ms 13564 KB Output is correct
59 Correct 16 ms 13564 KB Output is correct
60 Correct 22 ms 13564 KB Output is correct
61 Correct 20 ms 13564 KB Output is correct
62 Correct 46 ms 13564 KB Output is correct
63 Correct 123 ms 27512 KB Output is correct
64 Correct 130 ms 30836 KB Output is correct
65 Correct 179 ms 41412 KB Output is correct
66 Correct 282 ms 67212 KB Output is correct
67 Correct 288 ms 67304 KB Output is correct