Submission #49571

# Submission time Handle Problem Language Result Execution time Memory
49571 2018-05-31T10:48:59 Z hamzqq9 Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 34628 KB
#include<bits/stdc++.h>
#define lf double
#define ll long long
#define cc pair<char,char>
#define ull unsigned ll
#define ii pair<int,int>
#define li pair<ll,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define iiii2 pair<int,iii>
#define lii pair<ll,ii>
#define lolo pair<ll,ll>
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define umin(x,y) x=min(x,y)
#define umax(x,y) x=max(x,y)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define MOD 1000000007
#define inf 1000000005
#define M 10000002
#define N 30005
#define LOG 40
#define magic 100
#define KOK 250
#define EPS 0.0025
#define pw(x) ((1ll)<<(x))
#define PI 3.1415926535
using namespace std;

int n,m,b,p,from,to;
int dst[N];
vector<int> go[N];

int main() {
 
 	#if 0
	freopen("input.txt","r",stdin);
 	#endif

	scanf("%d %d",&n,&m);

	for(int i=1;i<=m;i++) {

		scanf("%d %d",&b,&p);

		go[b].pb(p);

		if(i==1) from=b;

		if(i==2) to=b;

	}

	for(int i=0;i<n;i++) {

		sort(all(go[i]));

		go[i].erase(unique(all(go[i])),go[i].end());

	}

	fill(dst,dst+N,inf);

	heap<ii> H;

	H.push({0,from});

	dst[from]=0;

	while(!H.empty()) {

		ii x=H.top();

		H.pop();

		if(dst[x.nd]<-x.st) continue ;

		if(x.nd==to) {

			printf("%d",dst[to]);
			
			return 0;

		}

		for(int p:go[x.nd]) {

			for(int i=x.nd+p;i<n;i+=p) {

				umin(dst[i],-x.st+(i-x.nd)/p);

				H.push({x.st-(i-x.nd)/p,i});

				if(binary_search(all(go[i]),p)) break ;


			}

			for(int i=x.nd-p;i>=0;i-=p) {

				umin(dst[i],-x.st+(x.nd-i)/p);

				H.push({x.st-(x.nd-i)/p,i});

				if(binary_search(all(go[i]),p)) break ;

			}

		} 

	}

	printf("-1");

}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
skyscraper.cpp:57:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&b,&p);
   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1144 KB Output is correct
2 Correct 3 ms 1352 KB Output is correct
3 Correct 2 ms 1352 KB Output is correct
4 Correct 2 ms 1352 KB Output is correct
5 Correct 2 ms 1352 KB Output is correct
6 Correct 3 ms 1352 KB Output is correct
7 Correct 2 ms 1352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1352 KB Output is correct
2 Correct 2 ms 1352 KB Output is correct
3 Correct 3 ms 1352 KB Output is correct
4 Correct 3 ms 1360 KB Output is correct
5 Correct 3 ms 1360 KB Output is correct
6 Correct 3 ms 1360 KB Output is correct
7 Correct 4 ms 1360 KB Output is correct
8 Correct 3 ms 1360 KB Output is correct
9 Correct 3 ms 1440 KB Output is correct
10 Correct 2 ms 1440 KB Output is correct
11 Correct 3 ms 1440 KB Output is correct
12 Correct 5 ms 1440 KB Output is correct
13 Correct 4 ms 1440 KB Output is correct
14 Correct 4 ms 1440 KB Output is correct
15 Correct 4 ms 1440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1440 KB Output is correct
2 Correct 4 ms 1440 KB Output is correct
3 Correct 3 ms 1440 KB Output is correct
4 Correct 3 ms 1440 KB Output is correct
5 Correct 3 ms 1440 KB Output is correct
6 Correct 3 ms 1440 KB Output is correct
7 Correct 3 ms 1444 KB Output is correct
8 Correct 3 ms 1444 KB Output is correct
9 Correct 3 ms 1444 KB Output is correct
10 Correct 3 ms 1444 KB Output is correct
11 Correct 3 ms 1472 KB Output is correct
12 Correct 3 ms 1472 KB Output is correct
13 Correct 4 ms 1472 KB Output is correct
14 Correct 5 ms 1472 KB Output is correct
15 Correct 4 ms 1472 KB Output is correct
16 Correct 3 ms 1472 KB Output is correct
17 Correct 8 ms 1788 KB Output is correct
18 Correct 3 ms 1788 KB Output is correct
19 Correct 3 ms 1788 KB Output is correct
20 Correct 4 ms 1788 KB Output is correct
21 Correct 3 ms 1788 KB Output is correct
22 Correct 3 ms 1788 KB Output is correct
23 Correct 4 ms 1788 KB Output is correct
24 Correct 6 ms 1788 KB Output is correct
25 Correct 4 ms 1788 KB Output is correct
26 Correct 3 ms 1788 KB Output is correct
27 Correct 3 ms 1788 KB Output is correct
28 Correct 5 ms 1788 KB Output is correct
29 Correct 15 ms 2040 KB Output is correct
30 Correct 7 ms 2040 KB Output is correct
31 Correct 10 ms 2040 KB Output is correct
32 Correct 8 ms 2040 KB Output is correct
33 Correct 33 ms 2512 KB Output is correct
34 Correct 20 ms 2556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2556 KB Output is correct
2 Correct 3 ms 2556 KB Output is correct
3 Correct 2 ms 2556 KB Output is correct
4 Correct 3 ms 2556 KB Output is correct
5 Correct 3 ms 2556 KB Output is correct
6 Correct 3 ms 2556 KB Output is correct
7 Correct 3 ms 2556 KB Output is correct
8 Correct 3 ms 2556 KB Output is correct
9 Correct 3 ms 2556 KB Output is correct
10 Correct 3 ms 2556 KB Output is correct
11 Correct 3 ms 2556 KB Output is correct
12 Correct 3 ms 2556 KB Output is correct
13 Correct 3 ms 2556 KB Output is correct
14 Correct 4 ms 2556 KB Output is correct
15 Correct 4 ms 2556 KB Output is correct
16 Correct 3 ms 2556 KB Output is correct
17 Correct 5 ms 2556 KB Output is correct
18 Correct 3 ms 2556 KB Output is correct
19 Correct 3 ms 2556 KB Output is correct
20 Correct 4 ms 2556 KB Output is correct
21 Correct 3 ms 2556 KB Output is correct
22 Correct 3 ms 2556 KB Output is correct
23 Correct 4 ms 2556 KB Output is correct
24 Correct 5 ms 2556 KB Output is correct
25 Correct 4 ms 2556 KB Output is correct
26 Correct 4 ms 2556 KB Output is correct
27 Correct 4 ms 2556 KB Output is correct
28 Correct 4 ms 2556 KB Output is correct
29 Correct 14 ms 2556 KB Output is correct
30 Correct 6 ms 2556 KB Output is correct
31 Correct 9 ms 2556 KB Output is correct
32 Correct 7 ms 2556 KB Output is correct
33 Correct 30 ms 2556 KB Output is correct
34 Correct 20 ms 2556 KB Output is correct
35 Correct 28 ms 3828 KB Output is correct
36 Correct 5 ms 3828 KB Output is correct
37 Correct 14 ms 3828 KB Output is correct
38 Correct 38 ms 5904 KB Output is correct
39 Correct 12 ms 5904 KB Output is correct
40 Correct 14 ms 5904 KB Output is correct
41 Correct 29 ms 5904 KB Output is correct
42 Correct 10 ms 5904 KB Output is correct
43 Correct 10 ms 5904 KB Output is correct
44 Correct 10 ms 5904 KB Output is correct
45 Correct 173 ms 9952 KB Output is correct
46 Correct 112 ms 9952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9952 KB Output is correct
2 Correct 3 ms 9952 KB Output is correct
3 Correct 3 ms 9952 KB Output is correct
4 Correct 3 ms 9952 KB Output is correct
5 Correct 3 ms 9952 KB Output is correct
6 Correct 3 ms 9952 KB Output is correct
7 Correct 3 ms 9952 KB Output is correct
8 Correct 3 ms 9952 KB Output is correct
9 Correct 3 ms 9952 KB Output is correct
10 Correct 3 ms 9952 KB Output is correct
11 Correct 3 ms 9952 KB Output is correct
12 Correct 3 ms 9952 KB Output is correct
13 Correct 4 ms 9952 KB Output is correct
14 Correct 4 ms 9952 KB Output is correct
15 Correct 4 ms 9952 KB Output is correct
16 Correct 3 ms 9952 KB Output is correct
17 Correct 5 ms 9952 KB Output is correct
18 Correct 3 ms 9952 KB Output is correct
19 Correct 3 ms 9952 KB Output is correct
20 Correct 3 ms 9952 KB Output is correct
21 Correct 3 ms 9952 KB Output is correct
22 Correct 3 ms 9952 KB Output is correct
23 Correct 4 ms 9952 KB Output is correct
24 Correct 5 ms 9952 KB Output is correct
25 Correct 4 ms 9952 KB Output is correct
26 Correct 4 ms 9952 KB Output is correct
27 Correct 5 ms 9952 KB Output is correct
28 Correct 5 ms 9952 KB Output is correct
29 Correct 15 ms 9952 KB Output is correct
30 Correct 6 ms 9952 KB Output is correct
31 Correct 9 ms 9952 KB Output is correct
32 Correct 7 ms 9952 KB Output is correct
33 Correct 32 ms 9952 KB Output is correct
34 Correct 21 ms 9952 KB Output is correct
35 Correct 26 ms 9952 KB Output is correct
36 Correct 4 ms 9952 KB Output is correct
37 Correct 16 ms 9952 KB Output is correct
38 Correct 37 ms 9952 KB Output is correct
39 Correct 12 ms 9952 KB Output is correct
40 Correct 14 ms 9952 KB Output is correct
41 Correct 42 ms 9952 KB Output is correct
42 Correct 16 ms 9952 KB Output is correct
43 Correct 9 ms 9952 KB Output is correct
44 Correct 14 ms 9952 KB Output is correct
45 Correct 169 ms 9952 KB Output is correct
46 Correct 110 ms 9952 KB Output is correct
47 Correct 23 ms 9952 KB Output is correct
48 Correct 18 ms 9952 KB Output is correct
49 Correct 11 ms 9952 KB Output is correct
50 Correct 9 ms 9952 KB Output is correct
51 Correct 36 ms 9952 KB Output is correct
52 Correct 44 ms 9952 KB Output is correct
53 Correct 17 ms 9952 KB Output is correct
54 Correct 5 ms 9952 KB Output is correct
55 Correct 6 ms 9952 KB Output is correct
56 Correct 17 ms 9952 KB Output is correct
57 Correct 5 ms 9952 KB Output is correct
58 Correct 16 ms 9952 KB Output is correct
59 Correct 17 ms 9952 KB Output is correct
60 Correct 16 ms 9952 KB Output is correct
61 Correct 17 ms 9952 KB Output is correct
62 Correct 51 ms 9952 KB Output is correct
63 Correct 856 ms 18268 KB Output is correct
64 Correct 907 ms 18268 KB Output is correct
65 Execution timed out 1077 ms 34628 KB Time limit exceeded
66 Halted 0 ms 0 KB -