Submission #328512

# Submission time Handle Problem Language Result Execution time Memory
328512 2020-11-16T19:55:48 Z negar_a Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
1000 ms 9324 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;
	}
	
	set <pii> s;
	s.insert({0, 0});
	
	while(s.size()){
		int x = s.begin() -> S;
		int w = s.begin() -> F;
		s.erase(s.begin());
//		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])){
	//						cout << "ii : " << i << " | " << d << " : " << d / p[x] << endl;
							s.erase({dis[u], u});
							dis[u] = dis[x] + (d / p[x]);
							s.insert({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.insert({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 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 7424 KB Output is correct
6 Correct 5 ms 7404 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 5 ms 7404 KB Output is correct
10 Correct 6 ms 7404 KB Output is correct
11 Correct 8 ms 7532 KB Output is correct
12 Correct 49 ms 7532 KB Output is correct
13 Correct 47 ms 7552 KB Output is correct
14 Correct 8 ms 7532 KB Output is correct
15 Correct 8 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 6 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 7 ms 7404 KB Output is correct
11 Correct 8 ms 7532 KB Output is correct
12 Correct 49 ms 7532 KB Output is correct
13 Correct 48 ms 7532 KB Output is correct
14 Correct 8 ms 7532 KB Output is correct
15 Correct 8 ms 7532 KB Output is correct
16 Correct 6 ms 7404 KB Output is correct
17 Correct 7 ms 7532 KB Output is correct
18 Correct 5 ms 7412 KB Output is correct
19 Correct 5 ms 7404 KB Output is correct
20 Correct 61 ms 7552 KB Output is correct
21 Correct 6 ms 7404 KB Output is correct
22 Correct 5 ms 7404 KB Output is correct
23 Correct 6 ms 7404 KB Output is correct
24 Correct 7 ms 7532 KB Output is correct
25 Correct 7 ms 7532 KB Output is correct
26 Correct 68 ms 7532 KB Output is correct
27 Correct 67 ms 7532 KB Output is correct
28 Correct 6 ms 7532 KB Output is correct
29 Correct 6 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 7404 KB Output is correct
33 Correct 9 ms 7532 KB Output is correct
34 Correct 9 ms 7532 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 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 6 ms 7404 KB Output is correct
10 Correct 6 ms 7404 KB Output is correct
11 Correct 8 ms 7532 KB Output is correct
12 Correct 49 ms 7532 KB Output is correct
13 Correct 48 ms 7532 KB Output is correct
14 Correct 8 ms 7532 KB Output is correct
15 Correct 8 ms 7532 KB Output is correct
16 Correct 5 ms 7404 KB Output is correct
17 Correct 7 ms 7532 KB Output is correct
18 Correct 5 ms 7404 KB Output is correct
19 Correct 5 ms 7404 KB Output is correct
20 Correct 61 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 6 ms 7404 KB Output is correct
24 Correct 7 ms 7532 KB Output is correct
25 Correct 7 ms 7532 KB Output is correct
26 Correct 70 ms 7532 KB Output is correct
27 Correct 67 ms 7532 KB Output is correct
28 Correct 6 ms 7532 KB Output is correct
29 Correct 6 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 9 ms 7532 KB Output is correct
34 Correct 9 ms 7532 KB Output is correct
35 Correct 56 ms 9068 KB Output is correct
36 Correct 10 ms 7660 KB Output is correct
37 Correct 54 ms 8684 KB Output is correct
38 Correct 79 ms 9324 KB Output is correct
39 Correct 71 ms 9324 KB Output is correct
40 Correct 78 ms 9324 KB Output is correct
41 Correct 74 ms 9324 KB Output is correct
42 Execution timed out 1067 ms 9324 KB Time limit exceeded
43 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 5 ms 7404 KB Output is correct
11 Correct 8 ms 7532 KB Output is correct
12 Correct 49 ms 7532 KB Output is correct
13 Correct 48 ms 7532 KB Output is correct
14 Correct 8 ms 7532 KB Output is correct
15 Correct 8 ms 7532 KB Output is correct
16 Correct 5 ms 7404 KB Output is correct
17 Correct 8 ms 7532 KB Output is correct
18 Correct 5 ms 7404 KB Output is correct
19 Correct 6 ms 7404 KB Output is correct
20 Correct 61 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 6 ms 7404 KB Output is correct
24 Correct 7 ms 7532 KB Output is correct
25 Correct 7 ms 7660 KB Output is correct
26 Correct 67 ms 7532 KB Output is correct
27 Correct 68 ms 7660 KB Output is correct
28 Correct 6 ms 7532 KB Output is correct
29 Correct 6 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 9 ms 7532 KB Output is correct
34 Correct 10 ms 7532 KB Output is correct
35 Correct 57 ms 9068 KB Output is correct
36 Correct 10 ms 7660 KB Output is correct
37 Correct 52 ms 8684 KB Output is correct
38 Correct 79 ms 9324 KB Output is correct
39 Correct 70 ms 9324 KB Output is correct
40 Correct 78 ms 9324 KB Output is correct
41 Correct 72 ms 9324 KB Output is correct
42 Execution timed out 1097 ms 9324 KB Time limit exceeded
43 Halted 0 ms 0 KB -