Submission #328514

# Submission time Handle Problem Language Result Execution time Memory
328514 2020-11-16T20:02:06 Z negar_a Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
1000 ms 8300 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second

const int maxn = 3e5 + 10;
int n, m;
int inf = 1e9;
int b[maxn], p[maxn];
vector <int> adj[maxn];
int dis[maxn];

int main(){
	fast_io;
	scanf("%d %d", &n, &m);
	for(int i = 0; i < m; i ++){
		scanf("%d %d", b + i, p + i);
		adj[b[i]].pb(i);
	}
	
	for(int i = 0; i <= m; i ++){
		dis[i] = inf;
	}
	
	priority_queue <pii> s;
	s.push({0, 0});
	
	while(s.size()){
		int x = s.top().S;
		int w = s.top().F;
		s.pop();
//		cout << "x : " << x << endl;
		if(dis[x] >= w){
			dis[x] = w;
			for(int i = b[x]; i <= n; i += p[x]){
				int d = abs(i - b[x]);
				if(d % p[x] == 0){
					for(int u : adj[i]){
						if(dis[u] > dis[x] + (d / p[x])){
							dis[u] = dis[x] + (d / p[x]);
							s.push({dis[u], u});
						}
					}
				}
			}
			for(int i = b[x]; i >= 0; i -= p[x]){
				int d = abs(i - b[x]);
				if(d % p[x] == 0){
					for(int u : adj[i]){
						if(dis[u] > dis[x] + (d / p[x])){
	//						cout << "ii : " << i << " | " << d << " : " << d / p[x] << endl;
//							s.erase({dis[u], u});
							dis[u] = dis[x] + (d / p[x]);
							s.push({dis[u], u});
						}
					}
				}
			}
		}
	}
	
	if(dis[1] != inf){
		printf("%d", dis[1]);
	}else{
		printf("%d", -1);
	}
	
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |   scanf("%d %d", b + i, p + i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 7 ms 7424 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 5 ms 7404 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 5 ms 7404 KB Output is correct
6 Correct 5 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 6 ms 7552 KB Output is correct
10 Correct 9 ms 7404 KB Output is correct
11 Correct 83 ms 7532 KB Output is correct
12 Correct 49 ms 7404 KB Output is correct
13 Correct 47 ms 7404 KB Output is correct
14 Correct 16 ms 7532 KB Output is correct
15 Correct 17 ms 7532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 5 ms 7404 KB Output is correct
6 Correct 6 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 8 ms 7404 KB Output is correct
11 Correct 84 ms 7532 KB Output is correct
12 Correct 49 ms 7404 KB Output is correct
13 Correct 47 ms 7404 KB Output is correct
14 Correct 16 ms 7552 KB Output is correct
15 Correct 17 ms 7532 KB Output is correct
16 Correct 6 ms 7404 KB Output is correct
17 Correct 163 ms 7532 KB Output is correct
18 Correct 6 ms 7404 KB Output is correct
19 Correct 5 ms 7404 KB Output is correct
20 Correct 60 ms 7580 KB Output is correct
21 Correct 6 ms 7404 KB Output is correct
22 Correct 5 ms 7404 KB Output is correct
23 Correct 10 ms 7424 KB Output is correct
24 Correct 55 ms 7532 KB Output is correct
25 Correct 12 ms 7660 KB Output is correct
26 Correct 132 ms 7552 KB Output is correct
27 Correct 67 ms 7404 KB Output is correct
28 Correct 6 ms 7532 KB Output is correct
29 Correct 9 ms 7404 KB Output is correct
30 Correct 5 ms 7404 KB Output is correct
31 Correct 6 ms 7404 KB Output is correct
32 Correct 6 ms 7404 KB Output is correct
33 Correct 22 ms 7532 KB Output is correct
34 Correct 23 ms 7532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 5 ms 7404 KB Output is correct
6 Correct 5 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 9 ms 7404 KB Output is correct
11 Correct 84 ms 7660 KB Output is correct
12 Correct 48 ms 7404 KB Output is correct
13 Correct 47 ms 7532 KB Output is correct
14 Correct 16 ms 7532 KB Output is correct
15 Correct 18 ms 7532 KB Output is correct
16 Correct 5 ms 7404 KB Output is correct
17 Correct 170 ms 7532 KB Output is correct
18 Correct 6 ms 7404 KB Output is correct
19 Correct 5 ms 7404 KB Output is correct
20 Correct 60 ms 7532 KB Output is correct
21 Correct 6 ms 7404 KB Output is correct
22 Correct 6 ms 7404 KB Output is correct
23 Correct 10 ms 7404 KB Output is correct
24 Correct 56 ms 7532 KB Output is correct
25 Correct 12 ms 7532 KB Output is correct
26 Correct 129 ms 7532 KB Output is correct
27 Correct 68 ms 7552 KB Output is correct
28 Correct 6 ms 7532 KB Output is correct
29 Correct 9 ms 7404 KB Output is correct
30 Correct 5 ms 7404 KB Output is correct
31 Correct 6 ms 7404 KB Output is correct
32 Correct 6 ms 7404 KB Output is correct
33 Correct 22 ms 7532 KB Output is correct
34 Correct 23 ms 7532 KB Output is correct
35 Execution timed out 1088 ms 8300 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 5 ms 7404 KB Output is correct
6 Correct 5 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 8 ms 7404 KB Output is correct
11 Correct 84 ms 7532 KB Output is correct
12 Correct 49 ms 7404 KB Output is correct
13 Correct 48 ms 7404 KB Output is correct
14 Correct 18 ms 7532 KB Output is correct
15 Correct 17 ms 7532 KB Output is correct
16 Correct 6 ms 7404 KB Output is correct
17 Correct 163 ms 7532 KB Output is correct
18 Correct 6 ms 7404 KB Output is correct
19 Correct 5 ms 7404 KB Output is correct
20 Correct 60 ms 7532 KB Output is correct
21 Correct 5 ms 7404 KB Output is correct
22 Correct 5 ms 7404 KB Output is correct
23 Correct 10 ms 7404 KB Output is correct
24 Correct 54 ms 7532 KB Output is correct
25 Correct 11 ms 7532 KB Output is correct
26 Correct 129 ms 7404 KB Output is correct
27 Correct 67 ms 7404 KB Output is correct
28 Correct 6 ms 7532 KB Output is correct
29 Correct 9 ms 7404 KB Output is correct
30 Correct 6 ms 7404 KB Output is correct
31 Correct 6 ms 7404 KB Output is correct
32 Correct 6 ms 7436 KB Output is correct
33 Correct 24 ms 7532 KB Output is correct
34 Correct 23 ms 7532 KB Output is correct
35 Execution timed out 1099 ms 8300 KB Time limit exceeded
36 Halted 0 ms 0 KB -