Submission #139242

# Submission time Handle Problem Language Result Execution time Memory
139242 2019-07-31T12:55:03 Z abacaba Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
339 ms 82016 KB
#include <bits/stdc++.h>
using namespace std;
 
const int inf = 2e9;
const int N = 3e4 + 15;
int n, m, d[N];
vector <pair <int, int> > g[N];
pair <int, int> a[N];
priority_queue <pair <int, int> > q;
unordered_set <int> used[N], is[N];

int main() {
	fill(d, d + N, inf);
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; ++i) {
    	scanf("%d%d", &a[i].first, &a[i].second);
   		is[a[i].first].insert(a[i].second);
    }
    for(int i = 0; i < m; ++i) {
    	int b = a[i].first, p = a[i].second;
    	int cnt = 0;
    	if(used[b].find(p) != used[b].end())
    		continue;
    	used[b].insert(p);
    	while(b - p >= 0) {
    		b -= p;
    		g[a[i].first].push_back({++cnt, b});
	    	if(is[b].find(p) != is[b].end())
	    		break;
    	}
    	b = a[i].first;
    	cnt = 0;
    	while(b + p < n) {
    		b += p;
    		g[a[i].first].push_back({++cnt, b});
	    	if(is[b].find(p) != is[b].end())
	    		break;
    	}
    }
    d[a[0].first] = 0;
    q.push({0, a[0].first});
    while(!q.empty()) {
    	int v = q.top().second, dist = -q.top().first;
    	q.pop();
    	if(dist > d[v])
    		continue;
    	for(pair <int, int> to : g[v]) {
    		if(d[to.second] > d[v] + to.first) {
    			d[to.second] = d[v] + to.first;
    			q.push({-d[to.second], to.second});
    		}
    	}
    }
    if(d[a[1].first] == inf)
    	puts("-1");
    else
    	printf("%d\n", d[a[1].first]);
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:14:10: 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:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
      scanf("%d%d", &a[i].first, &a[i].second);
      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4472 KB Output is correct
2 Correct 6 ms 4472 KB Output is correct
3 Correct 6 ms 4472 KB Output is correct
4 Correct 6 ms 4472 KB Output is correct
5 Correct 6 ms 4472 KB Output is correct
6 Correct 6 ms 4472 KB Output is correct
7 Correct 6 ms 4472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4476 KB Output is correct
2 Correct 6 ms 4472 KB Output is correct
3 Correct 6 ms 4472 KB Output is correct
4 Correct 6 ms 4472 KB Output is correct
5 Correct 6 ms 4472 KB Output is correct
6 Correct 7 ms 4372 KB Output is correct
7 Correct 6 ms 4472 KB Output is correct
8 Correct 6 ms 4472 KB Output is correct
9 Correct 6 ms 4472 KB Output is correct
10 Correct 6 ms 4472 KB Output is correct
11 Correct 7 ms 4600 KB Output is correct
12 Correct 20 ms 4472 KB Output is correct
13 Correct 8 ms 4472 KB Output is correct
14 Correct 8 ms 4736 KB Output is correct
15 Correct 7 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4472 KB Output is correct
2 Correct 6 ms 4476 KB Output is correct
3 Correct 7 ms 4344 KB Output is correct
4 Correct 6 ms 4472 KB Output is correct
5 Correct 6 ms 4344 KB Output is correct
6 Correct 6 ms 4472 KB Output is correct
7 Correct 6 ms 4472 KB Output is correct
8 Correct 6 ms 4472 KB Output is correct
9 Correct 6 ms 4472 KB Output is correct
10 Correct 6 ms 4472 KB Output is correct
11 Correct 7 ms 4728 KB Output is correct
12 Correct 5 ms 4472 KB Output is correct
13 Correct 6 ms 4472 KB Output is correct
14 Correct 7 ms 4728 KB Output is correct
15 Correct 7 ms 4728 KB Output is correct
16 Correct 7 ms 4600 KB Output is correct
17 Correct 9 ms 4856 KB Output is correct
18 Correct 7 ms 4600 KB Output is correct
19 Correct 7 ms 4600 KB Output is correct
20 Correct 8 ms 4728 KB Output is correct
21 Correct 7 ms 4596 KB Output is correct
22 Correct 7 ms 4600 KB Output is correct
23 Correct 7 ms 4600 KB Output is correct
24 Correct 9 ms 4728 KB Output is correct
25 Correct 8 ms 4808 KB Output is correct
26 Correct 7 ms 4600 KB Output is correct
27 Correct 7 ms 4600 KB Output is correct
28 Correct 8 ms 4856 KB Output is correct
29 Correct 9 ms 5368 KB Output is correct
30 Correct 7 ms 4728 KB Output is correct
31 Correct 8 ms 4984 KB Output is correct
32 Correct 8 ms 4860 KB Output is correct
33 Correct 11 ms 6008 KB Output is correct
34 Correct 12 ms 6008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4472 KB Output is correct
2 Correct 6 ms 4472 KB Output is correct
3 Correct 6 ms 4472 KB Output is correct
4 Correct 6 ms 4344 KB Output is correct
5 Correct 6 ms 4472 KB Output is correct
6 Correct 6 ms 4472 KB Output is correct
7 Correct 6 ms 4472 KB Output is correct
8 Correct 6 ms 4476 KB Output is correct
9 Correct 6 ms 4472 KB Output is correct
10 Correct 6 ms 4472 KB Output is correct
11 Correct 7 ms 4728 KB Output is correct
12 Correct 6 ms 4444 KB Output is correct
13 Correct 6 ms 4472 KB Output is correct
14 Correct 7 ms 4728 KB Output is correct
15 Correct 7 ms 4600 KB Output is correct
16 Correct 7 ms 4600 KB Output is correct
17 Correct 9 ms 4856 KB Output is correct
18 Correct 7 ms 4600 KB Output is correct
19 Correct 6 ms 4472 KB Output is correct
20 Correct 8 ms 4728 KB Output is correct
21 Correct 8 ms 4600 KB Output is correct
22 Correct 7 ms 4572 KB Output is correct
23 Correct 8 ms 4600 KB Output is correct
24 Correct 9 ms 4848 KB Output is correct
25 Correct 8 ms 4856 KB Output is correct
26 Correct 7 ms 4600 KB Output is correct
27 Correct 7 ms 4476 KB Output is correct
28 Correct 9 ms 4856 KB Output is correct
29 Correct 11 ms 5240 KB Output is correct
30 Correct 8 ms 4728 KB Output is correct
31 Correct 9 ms 4856 KB Output is correct
32 Correct 9 ms 4856 KB Output is correct
33 Correct 12 ms 6008 KB Output is correct
34 Correct 12 ms 6008 KB Output is correct
35 Correct 38 ms 8056 KB Output is correct
36 Correct 11 ms 5112 KB Output is correct
37 Correct 39 ms 8440 KB Output is correct
38 Correct 48 ms 9208 KB Output is correct
39 Correct 51 ms 9228 KB Output is correct
40 Correct 50 ms 9208 KB Output is correct
41 Correct 51 ms 9080 KB Output is correct
42 Correct 13 ms 4856 KB Output is correct
43 Correct 13 ms 4728 KB Output is correct
44 Correct 13 ms 4984 KB Output is correct
45 Correct 47 ms 11848 KB Output is correct
46 Correct 67 ms 11740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4472 KB Output is correct
2 Correct 7 ms 4344 KB Output is correct
3 Correct 7 ms 4472 KB Output is correct
4 Correct 6 ms 4348 KB Output is correct
5 Correct 7 ms 4472 KB Output is correct
6 Correct 7 ms 4472 KB Output is correct
7 Correct 6 ms 4472 KB Output is correct
8 Correct 6 ms 4472 KB Output is correct
9 Correct 6 ms 4472 KB Output is correct
10 Correct 6 ms 4472 KB Output is correct
11 Correct 10 ms 4600 KB Output is correct
12 Correct 6 ms 4472 KB Output is correct
13 Correct 6 ms 4472 KB Output is correct
14 Correct 7 ms 4600 KB Output is correct
15 Correct 7 ms 4600 KB Output is correct
16 Correct 7 ms 4600 KB Output is correct
17 Correct 10 ms 4860 KB Output is correct
18 Correct 7 ms 4600 KB Output is correct
19 Correct 6 ms 4472 KB Output is correct
20 Correct 8 ms 4728 KB Output is correct
21 Correct 7 ms 4600 KB Output is correct
22 Correct 7 ms 4600 KB Output is correct
23 Correct 7 ms 4600 KB Output is correct
24 Correct 9 ms 4856 KB Output is correct
25 Correct 8 ms 4856 KB Output is correct
26 Correct 7 ms 4604 KB Output is correct
27 Correct 7 ms 4600 KB Output is correct
28 Correct 9 ms 4984 KB Output is correct
29 Correct 9 ms 5368 KB Output is correct
30 Correct 7 ms 4728 KB Output is correct
31 Correct 8 ms 5112 KB Output is correct
32 Correct 8 ms 4860 KB Output is correct
33 Correct 12 ms 6008 KB Output is correct
34 Correct 12 ms 6008 KB Output is correct
35 Correct 37 ms 7928 KB Output is correct
36 Correct 11 ms 5112 KB Output is correct
37 Correct 38 ms 8440 KB Output is correct
38 Correct 47 ms 9080 KB Output is correct
39 Correct 47 ms 9080 KB Output is correct
40 Correct 49 ms 9080 KB Output is correct
41 Correct 47 ms 9080 KB Output is correct
42 Correct 12 ms 4856 KB Output is correct
43 Correct 12 ms 4728 KB Output is correct
44 Correct 14 ms 5112 KB Output is correct
45 Correct 47 ms 11772 KB Output is correct
46 Correct 46 ms 11640 KB Output is correct
47 Correct 104 ms 16224 KB Output is correct
48 Correct 46 ms 9332 KB Output is correct
49 Correct 36 ms 8312 KB Output is correct
50 Correct 28 ms 7672 KB Output is correct
51 Correct 89 ms 11892 KB Output is correct
52 Correct 82 ms 12172 KB Output is correct
53 Correct 47 ms 9460 KB Output is correct
54 Correct 8 ms 4856 KB Output is correct
55 Correct 10 ms 5364 KB Output is correct
56 Correct 50 ms 9336 KB Output is correct
57 Correct 60 ms 13564 KB Output is correct
58 Correct 18 ms 5940 KB Output is correct
59 Correct 18 ms 6016 KB Output is correct
60 Correct 21 ms 6644 KB Output is correct
61 Correct 21 ms 6260 KB Output is correct
62 Correct 75 ms 13556 KB Output is correct
63 Correct 142 ms 31792 KB Output is correct
64 Correct 161 ms 41292 KB Output is correct
65 Correct 218 ms 52692 KB Output is correct
66 Correct 339 ms 81852 KB Output is correct
67 Correct 330 ms 82016 KB Output is correct