Submission #335258

# Submission time Handle Problem Language Result Execution time Memory
335258 2020-12-11T17:38:14 Z hivakarami Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
899 ms 3808 KB
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double doublel;
#define f first
#define s second
 
const int N = 3e4 + 100;
const ll mod = 1e9 + 9;	
const int inf = 1e8;	

int dis[N];
vector<int> adj[N];
priority_queue<pair<int, int>> q;

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

	int n, m, z, y;
	scanf("%d %d", &n, &m);
	
	for(int i = 0; i < m; i++)
	{
		int p, b;
		scanf("%d %d", &b, &p);
		adj[b].push_back(p);
		
		if(i == 0)
			z = b;
		else if(i == 1)
			y = b;
	}
	
	for(int i = 0; i < n; i++)	
		dis[i] = inf;
	dis[z] = 0;
	
	q.push({0, z});	
	
	while(!q.empty())
	{	
		int x = q.top().s;
		q.pop();
		
		for(auto p : adj[x])
		{
			int c = 1;
			for(int i = x+p; i < n; i += p)
			{
				if(dis[i] > dis[x] + c)
				{
					dis[i] = dis[x] + c;
					if(y != i) q.push({-dis[i], i});
				}
				
				c++;
			}
			c = 1;	
			for(int i = x-p; i >= 0; i -= p)
			{
				if(dis[i] > dis[x] + c)
				{
					dis[i] = dis[x] + c;
					if(y != i) q.push({-dis[i], i});
				}
				
				c++;
			}
		}
		
	}
	
	
	if(dis[y] >= inf)
		dis[y] = -1;
	printf("%d \n", dis[y]);	
	
	
	

    return 0;
}

 
 	





 

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |   scanf("%d %d", &b, &p);
      |   ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:22:12: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
   22 |  int n, m, z, y;
      |            ^
skyscraper.cpp:79:8: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   79 |  printf("%d \n", dis[y]);
      |  ~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
8 Correct 1 ms 1004 KB Output is correct
9 Correct 1 ms 1004 KB Output is correct
10 Correct 1 ms 1004 KB Output is correct
11 Correct 2 ms 1132 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 1 ms 1132 KB Output is correct
15 Correct 1 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
8 Correct 1 ms 1004 KB Output is correct
9 Correct 1 ms 1024 KB Output is correct
10 Correct 1 ms 1004 KB Output is correct
11 Correct 2 ms 1132 KB Output is correct
12 Correct 2 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 2 ms 1132 KB Output is correct
15 Correct 2 ms 1132 KB Output is correct
16 Correct 1 ms 1004 KB Output is correct
17 Correct 2 ms 1132 KB Output is correct
18 Correct 1 ms 1132 KB Output is correct
19 Correct 1 ms 1132 KB Output is correct
20 Correct 6 ms 1132 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 1132 KB Output is correct
23 Correct 2 ms 1132 KB Output is correct
24 Correct 3 ms 1132 KB Output is correct
25 Correct 2 ms 1132 KB Output is correct
26 Correct 1 ms 1132 KB Output is correct
27 Correct 2 ms 1132 KB Output is correct
28 Correct 2 ms 1132 KB Output is correct
29 Correct 2 ms 1132 KB Output is correct
30 Correct 2 ms 1132 KB Output is correct
31 Correct 2 ms 1132 KB Output is correct
32 Correct 2 ms 1132 KB Output is correct
33 Correct 3 ms 1260 KB Output is correct
34 Correct 3 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 2 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
8 Correct 1 ms 1004 KB Output is correct
9 Correct 1 ms 1004 KB Output is correct
10 Correct 1 ms 1004 KB Output is correct
11 Correct 2 ms 1132 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 2 ms 1132 KB Output is correct
15 Correct 1 ms 1132 KB Output is correct
16 Correct 1 ms 1004 KB Output is correct
17 Correct 2 ms 1132 KB Output is correct
18 Correct 1 ms 1132 KB Output is correct
19 Correct 1 ms 1132 KB Output is correct
20 Correct 6 ms 1132 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 1132 KB Output is correct
23 Correct 2 ms 1132 KB Output is correct
24 Correct 2 ms 1132 KB Output is correct
25 Correct 2 ms 1132 KB Output is correct
26 Correct 2 ms 1132 KB Output is correct
27 Correct 2 ms 1132 KB Output is correct
28 Correct 2 ms 1132 KB Output is correct
29 Correct 2 ms 1132 KB Output is correct
30 Correct 2 ms 1132 KB Output is correct
31 Correct 2 ms 1132 KB Output is correct
32 Correct 2 ms 1132 KB Output is correct
33 Correct 3 ms 1260 KB Output is correct
34 Correct 3 ms 1260 KB Output is correct
35 Correct 9 ms 1516 KB Output is correct
36 Correct 3 ms 1132 KB Output is correct
37 Correct 9 ms 1516 KB Output is correct
38 Correct 12 ms 1644 KB Output is correct
39 Correct 12 ms 1644 KB Output is correct
40 Correct 12 ms 1644 KB Output is correct
41 Correct 12 ms 1644 KB Output is correct
42 Correct 8 ms 1644 KB Output is correct
43 Correct 7 ms 1516 KB Output is correct
44 Correct 64 ms 1516 KB Output is correct
45 Correct 11 ms 1644 KB Output is correct
46 Correct 11 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
8 Correct 1 ms 1004 KB Output is correct
9 Correct 1 ms 1004 KB Output is correct
10 Correct 1 ms 1004 KB Output is correct
11 Correct 2 ms 1132 KB Output is correct
12 Correct 1 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 2 ms 1132 KB Output is correct
15 Correct 1 ms 1132 KB Output is correct
16 Correct 2 ms 1004 KB Output is correct
17 Correct 2 ms 1132 KB Output is correct
18 Correct 1 ms 1132 KB Output is correct
19 Correct 1 ms 1132 KB Output is correct
20 Correct 6 ms 1132 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 1132 KB Output is correct
23 Correct 2 ms 1132 KB Output is correct
24 Correct 2 ms 1132 KB Output is correct
25 Correct 2 ms 1132 KB Output is correct
26 Correct 2 ms 1132 KB Output is correct
27 Correct 1 ms 1132 KB Output is correct
28 Correct 2 ms 1132 KB Output is correct
29 Correct 2 ms 1132 KB Output is correct
30 Correct 2 ms 1132 KB Output is correct
31 Correct 2 ms 1132 KB Output is correct
32 Correct 35 ms 1132 KB Output is correct
33 Correct 3 ms 1260 KB Output is correct
34 Correct 3 ms 1260 KB Output is correct
35 Correct 42 ms 1516 KB Output is correct
36 Correct 3 ms 1132 KB Output is correct
37 Correct 42 ms 1516 KB Output is correct
38 Correct 12 ms 1644 KB Output is correct
39 Correct 12 ms 1644 KB Output is correct
40 Correct 12 ms 1644 KB Output is correct
41 Correct 12 ms 1644 KB Output is correct
42 Correct 7 ms 1516 KB Output is correct
43 Correct 7 ms 1516 KB Output is correct
44 Correct 66 ms 1516 KB Output is correct
45 Correct 11 ms 1644 KB Output is correct
46 Correct 11 ms 1644 KB Output is correct
47 Correct 26 ms 2280 KB Output is correct
48 Correct 8 ms 1772 KB Output is correct
49 Correct 8 ms 1900 KB Output is correct
50 Correct 6 ms 1644 KB Output is correct
51 Correct 36 ms 3300 KB Output is correct
52 Correct 32 ms 2792 KB Output is correct
53 Correct 13 ms 2284 KB Output is correct
54 Correct 2 ms 1388 KB Output is correct
55 Correct 3 ms 1388 KB Output is correct
56 Correct 867 ms 2672 KB Output is correct
57 Correct 90 ms 3424 KB Output is correct
58 Correct 899 ms 1644 KB Output is correct
59 Correct 9 ms 1772 KB Output is correct
60 Correct 9 ms 1772 KB Output is correct
61 Correct 9 ms 1772 KB Output is correct
62 Correct 13 ms 2412 KB Output is correct
63 Correct 28 ms 2792 KB Output is correct
64 Correct 29 ms 2788 KB Output is correct
65 Correct 34 ms 2792 KB Output is correct
66 Correct 59 ms 3808 KB Output is correct
67 Correct 59 ms 3808 KB Output is correct