Submission #49572

# Submission time Handle Problem Language Result Execution time Memory
49572 2018-05-31T10:52:00 Z hamzqq9 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
131 ms 3820 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) {

				if(dst[i]>-x.st+(i-x.nd)/p) H.push({-(dst[i]=-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) {

				if(dst[i]>-x.st+(x.nd-i)/p) H.push({-(dst[i]=-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 3 ms 1144 KB Output is correct
2 Correct 3 ms 1320 KB Output is correct
3 Correct 3 ms 1320 KB Output is correct
4 Correct 3 ms 1320 KB Output is correct
5 Correct 3 ms 1320 KB Output is correct
6 Correct 3 ms 1364 KB Output is correct
7 Correct 3 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1364 KB Output is correct
2 Correct 3 ms 1364 KB Output is correct
3 Correct 3 ms 1364 KB Output is correct
4 Correct 3 ms 1496 KB Output is correct
5 Correct 4 ms 1496 KB Output is correct
6 Correct 3 ms 1496 KB Output is correct
7 Correct 2 ms 1496 KB Output is correct
8 Correct 3 ms 1496 KB Output is correct
9 Correct 4 ms 1496 KB Output is correct
10 Correct 3 ms 1496 KB Output is correct
11 Correct 4 ms 1496 KB Output is correct
12 Correct 3 ms 1496 KB Output is correct
13 Correct 3 ms 1496 KB Output is correct
14 Correct 3 ms 1496 KB Output is correct
15 Correct 3 ms 1496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1496 KB Output is correct
2 Correct 3 ms 1496 KB Output is correct
3 Correct 3 ms 1496 KB Output is correct
4 Correct 3 ms 1516 KB Output is correct
5 Correct 3 ms 1516 KB Output is correct
6 Correct 3 ms 1516 KB Output is correct
7 Correct 4 ms 1516 KB Output is correct
8 Correct 3 ms 1516 KB Output is correct
9 Correct 3 ms 1516 KB Output is correct
10 Correct 3 ms 1516 KB Output is correct
11 Correct 5 ms 1516 KB Output is correct
12 Correct 3 ms 1516 KB Output is correct
13 Correct 3 ms 1516 KB Output is correct
14 Correct 4 ms 1516 KB Output is correct
15 Correct 4 ms 1516 KB Output is correct
16 Correct 3 ms 1516 KB Output is correct
17 Correct 4 ms 1516 KB Output is correct
18 Correct 5 ms 1516 KB Output is correct
19 Correct 3 ms 1516 KB Output is correct
20 Correct 4 ms 1516 KB Output is correct
21 Correct 3 ms 1516 KB Output is correct
22 Correct 3 ms 1516 KB Output is correct
23 Correct 4 ms 1516 KB Output is correct
24 Correct 5 ms 1516 KB Output is correct
25 Correct 4 ms 1516 KB Output is correct
26 Correct 3 ms 1516 KB Output is correct
27 Correct 3 ms 1516 KB Output is correct
28 Correct 4 ms 1516 KB Output is correct
29 Correct 5 ms 1532 KB Output is correct
30 Correct 4 ms 1532 KB Output is correct
31 Correct 4 ms 1532 KB Output is correct
32 Correct 4 ms 1556 KB Output is correct
33 Correct 6 ms 1684 KB Output is correct
34 Correct 5 ms 1688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1688 KB Output is correct
2 Correct 4 ms 1688 KB Output is correct
3 Correct 3 ms 1688 KB Output is correct
4 Correct 3 ms 1688 KB Output is correct
5 Correct 3 ms 1688 KB Output is correct
6 Correct 3 ms 1688 KB Output is correct
7 Correct 3 ms 1688 KB Output is correct
8 Correct 3 ms 1688 KB Output is correct
9 Correct 3 ms 1688 KB Output is correct
10 Correct 3 ms 1688 KB Output is correct
11 Correct 3 ms 1688 KB Output is correct
12 Correct 3 ms 1688 KB Output is correct
13 Correct 3 ms 1688 KB Output is correct
14 Correct 4 ms 1688 KB Output is correct
15 Correct 3 ms 1688 KB Output is correct
16 Correct 3 ms 1688 KB Output is correct
17 Correct 4 ms 1688 KB Output is correct
18 Correct 3 ms 1688 KB Output is correct
19 Correct 3 ms 1688 KB Output is correct
20 Correct 3 ms 1688 KB Output is correct
21 Correct 3 ms 1688 KB Output is correct
22 Correct 4 ms 1688 KB Output is correct
23 Correct 3 ms 1688 KB Output is correct
24 Correct 5 ms 1688 KB Output is correct
25 Correct 4 ms 1688 KB Output is correct
26 Correct 4 ms 1688 KB Output is correct
27 Correct 4 ms 1688 KB Output is correct
28 Correct 4 ms 1688 KB Output is correct
29 Correct 4 ms 1688 KB Output is correct
30 Correct 4 ms 1688 KB Output is correct
31 Correct 5 ms 1688 KB Output is correct
32 Correct 4 ms 1688 KB Output is correct
33 Correct 5 ms 1688 KB Output is correct
34 Correct 4 ms 1688 KB Output is correct
35 Correct 12 ms 1688 KB Output is correct
36 Correct 4 ms 1688 KB Output is correct
37 Correct 11 ms 1688 KB Output is correct
38 Correct 16 ms 1788 KB Output is correct
39 Correct 12 ms 1788 KB Output is correct
40 Correct 14 ms 1788 KB Output is correct
41 Correct 17 ms 1788 KB Output is correct
42 Correct 9 ms 1788 KB Output is correct
43 Correct 9 ms 1788 KB Output is correct
44 Correct 9 ms 1788 KB Output is correct
45 Correct 16 ms 1792 KB Output is correct
46 Correct 16 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1792 KB Output is correct
2 Correct 3 ms 1792 KB Output is correct
3 Correct 3 ms 1792 KB Output is correct
4 Correct 2 ms 1792 KB Output is correct
5 Correct 3 ms 1792 KB Output is correct
6 Correct 3 ms 1792 KB Output is correct
7 Correct 4 ms 1792 KB Output is correct
8 Correct 3 ms 1792 KB Output is correct
9 Correct 3 ms 1792 KB Output is correct
10 Correct 3 ms 1792 KB Output is correct
11 Correct 4 ms 1792 KB Output is correct
12 Correct 3 ms 1792 KB Output is correct
13 Correct 3 ms 1792 KB Output is correct
14 Correct 3 ms 1792 KB Output is correct
15 Correct 4 ms 1792 KB Output is correct
16 Correct 4 ms 1792 KB Output is correct
17 Correct 4 ms 1792 KB Output is correct
18 Correct 3 ms 1792 KB Output is correct
19 Correct 4 ms 1792 KB Output is correct
20 Correct 4 ms 1792 KB Output is correct
21 Correct 3 ms 1792 KB Output is correct
22 Correct 2 ms 1792 KB Output is correct
23 Correct 3 ms 1792 KB Output is correct
24 Correct 4 ms 1792 KB Output is correct
25 Correct 4 ms 1792 KB Output is correct
26 Correct 3 ms 1792 KB Output is correct
27 Correct 4 ms 1792 KB Output is correct
28 Correct 4 ms 1792 KB Output is correct
29 Correct 5 ms 1792 KB Output is correct
30 Correct 5 ms 1792 KB Output is correct
31 Correct 4 ms 1792 KB Output is correct
32 Correct 4 ms 1792 KB Output is correct
33 Correct 6 ms 1792 KB Output is correct
34 Correct 5 ms 1792 KB Output is correct
35 Correct 13 ms 1792 KB Output is correct
36 Correct 4 ms 1792 KB Output is correct
37 Correct 10 ms 1792 KB Output is correct
38 Correct 17 ms 1792 KB Output is correct
39 Correct 13 ms 1792 KB Output is correct
40 Correct 13 ms 1792 KB Output is correct
41 Correct 17 ms 1792 KB Output is correct
42 Correct 10 ms 1792 KB Output is correct
43 Correct 10 ms 1792 KB Output is correct
44 Correct 11 ms 1792 KB Output is correct
45 Correct 16 ms 1792 KB Output is correct
46 Correct 18 ms 1792 KB Output is correct
47 Correct 18 ms 2172 KB Output is correct
48 Correct 12 ms 2172 KB Output is correct
49 Correct 13 ms 2172 KB Output is correct
50 Correct 9 ms 2172 KB Output is correct
51 Correct 28 ms 2684 KB Output is correct
52 Correct 29 ms 2684 KB Output is correct
53 Correct 16 ms 2684 KB Output is correct
54 Correct 5 ms 2684 KB Output is correct
55 Correct 6 ms 2684 KB Output is correct
56 Correct 15 ms 2684 KB Output is correct
57 Correct 4 ms 2684 KB Output is correct
58 Correct 12 ms 2684 KB Output is correct
59 Correct 18 ms 2684 KB Output is correct
60 Correct 12 ms 2684 KB Output is correct
61 Correct 14 ms 2684 KB Output is correct
62 Correct 23 ms 2684 KB Output is correct
63 Correct 62 ms 2808 KB Output is correct
64 Correct 45 ms 2808 KB Output is correct
65 Correct 61 ms 2808 KB Output is correct
66 Correct 131 ms 3820 KB Output is correct
67 Correct 71 ms 3820 KB Output is correct