Submission #527447

# Submission time Handle Problem Language Result Execution time Memory
527447 2022-02-17T12:31:56 Z Koosha_mv Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 201900 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=50000,S=100;

int m,n,pos[N],p[N],dist[N][S];
vector<int> vec[N];
set<pair<int,pair<int,int>>> st;

main(){
	ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
	cin>>n>>m;
	f(i,0,m){
		cin>>pos[i]>>p[i];
		vec[pos[i]].pb(p[i]);
	}
	f(i,0,n) f(j,0,S) dist[i][j]=N;
	dist[pos[0]][0]=0;
	f(i,0,n) f(j,0,S) st.insert({dist[i][j],{i,j}});
	while(st.size()){
		int x=(*st.begin()).S.F,p=(*st.begin()).S.S;
		if(dist[x][p]==N) break;
		//cout<<endl;
		//eror(dist[2][0]);
		//cout<<x<<" "<<p<<" -> "<<dist[x][p]<<endl;
		st.erase(*st.begin());
		if(p>0){
			//eror(x+p);
			//cout<<x+p<<" "<<dist[x][p]+1<<" "<<dist[x+p][0]<<endl;
			if(x+p<n && dist[x][p]+1<dist[x+p][0]){
				//eror(100);
				st.erase({dist[x+p][0],{x+p,0}});
				dist[x+p][0]=dist[x][p]+1;
				st.insert({dist[x+p][0],{x+p,0}});
			}
			if(p<=x && dist[x][p]+1<dist[x-p][0]){
				st.erase({dist[x-p][0],{x-p,0}});
				dist[x-p][0]=dist[x][p]+1;
				st.insert({dist[x-p][0],{x-p,0}});
			}
			
			if(x+p<n && dist[x][p]+1<dist[x+p][p]){
				st.erase({dist[x+p][p],{x+p,p}});
				dist[x+p][p]=dist[x][p]+1;
				st.insert({dist[x+p][p],{x+p,p}});
			}
			if(p<=x && dist[x][p]+1<dist[x-p][p]){
				st.erase({dist[x-p][p],{x-p,p}});
				dist[x-p][p]=dist[x][p]+1;
				st.insert({dist[x-p][p],{x-p,p}});
			}
			continue ;
		}
		for(auto u : vec[x]){
			if(u<S){
				if(dist[x][u]<=dist[x][p]) continue ;
				st.erase({dist[x][u],{x,u}});
				dist[x][u]=dist[x][p];
				st.insert({dist[x][u],{x,u}});
			}
			else{
				for(int i=x%u;i<n;i+=u){
					if(dist[x][p]+abs(x-i)/u<dist[i][p]){
						st.erase({dist[i][p],{i,p}});
						dist[i][p]=dist[x][p]+abs(x-i)/u;
						st.insert({dist[i][p],{i,p}});
					}
				}
			}
		}
	}
	cout<<(dist[pos[1]][0]==N ? -1 : dist[pos[1]][0]);
}

Compilation message

skyscraper.cpp:29:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   29 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 2 ms 1740 KB Output is correct
9 Correct 2 ms 1868 KB Output is correct
10 Correct 3 ms 2124 KB Output is correct
11 Correct 5 ms 2124 KB Output is correct
12 Correct 3 ms 2124 KB Output is correct
13 Correct 3 ms 2124 KB Output is correct
14 Correct 5 ms 2124 KB Output is correct
15 Correct 5 ms 2124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 2 ms 1740 KB Output is correct
9 Correct 2 ms 1868 KB Output is correct
10 Correct 4 ms 2064 KB Output is correct
11 Correct 6 ms 2124 KB Output is correct
12 Correct 3 ms 2124 KB Output is correct
13 Correct 4 ms 2124 KB Output is correct
14 Correct 5 ms 2124 KB Output is correct
15 Correct 8 ms 2132 KB Output is correct
16 Correct 7 ms 2764 KB Output is correct
17 Correct 25 ms 6476 KB Output is correct
18 Correct 41 ms 13044 KB Output is correct
19 Correct 49 ms 14788 KB Output is correct
20 Correct 50 ms 14788 KB Output is correct
21 Correct 11 ms 4148 KB Output is correct
22 Correct 56 ms 13348 KB Output is correct
23 Correct 47 ms 12092 KB Output is correct
24 Correct 63 ms 14156 KB Output is correct
25 Correct 57 ms 14788 KB Output is correct
26 Correct 58 ms 14720 KB Output is correct
27 Correct 59 ms 14732 KB Output is correct
28 Correct 61 ms 14788 KB Output is correct
29 Correct 88 ms 14692 KB Output is correct
30 Correct 64 ms 14916 KB Output is correct
31 Correct 72 ms 14796 KB Output is correct
32 Correct 78 ms 14784 KB Output is correct
33 Correct 119 ms 14804 KB Output is correct
34 Correct 108 ms 14788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 2 ms 1484 KB Output is correct
8 Correct 2 ms 1740 KB Output is correct
9 Correct 2 ms 1868 KB Output is correct
10 Correct 3 ms 2124 KB Output is correct
11 Correct 5 ms 2124 KB Output is correct
12 Correct 3 ms 2124 KB Output is correct
13 Correct 4 ms 2124 KB Output is correct
14 Correct 5 ms 2124 KB Output is correct
15 Correct 6 ms 2172 KB Output is correct
16 Correct 4 ms 2764 KB Output is correct
17 Correct 25 ms 6424 KB Output is correct
18 Correct 43 ms 13124 KB Output is correct
19 Correct 49 ms 14704 KB Output is correct
20 Correct 51 ms 14860 KB Output is correct
21 Correct 11 ms 4040 KB Output is correct
22 Correct 44 ms 13296 KB Output is correct
23 Correct 47 ms 12136 KB Output is correct
24 Correct 58 ms 14100 KB Output is correct
25 Correct 62 ms 14836 KB Output is correct
26 Correct 57 ms 14696 KB Output is correct
27 Correct 59 ms 14696 KB Output is correct
28 Correct 77 ms 14788 KB Output is correct
29 Correct 86 ms 14796 KB Output is correct
30 Correct 60 ms 14760 KB Output is correct
31 Correct 71 ms 14788 KB Output is correct
32 Correct 76 ms 14696 KB Output is correct
33 Correct 121 ms 14788 KB Output is correct
34 Correct 110 ms 14824 KB Output is correct
35 Correct 74 ms 11416 KB Output is correct
36 Correct 33 ms 8784 KB Output is correct
37 Correct 123 ms 14600 KB Output is correct
38 Correct 134 ms 15220 KB Output is correct
39 Correct 132 ms 15232 KB Output is correct
40 Correct 137 ms 15128 KB Output is correct
41 Correct 120 ms 15120 KB Output is correct
42 Correct 65 ms 15116 KB Output is correct
43 Correct 77 ms 15140 KB Output is correct
44 Correct 72 ms 15128 KB Output is correct
45 Correct 149 ms 15152 KB Output is correct
46 Correct 140 ms 15208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 2 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 2 ms 1740 KB Output is correct
9 Correct 2 ms 1868 KB Output is correct
10 Correct 3 ms 2124 KB Output is correct
11 Correct 5 ms 2124 KB Output is correct
12 Correct 3 ms 2172 KB Output is correct
13 Correct 3 ms 2124 KB Output is correct
14 Correct 5 ms 2124 KB Output is correct
15 Correct 5 ms 2124 KB Output is correct
16 Correct 5 ms 2764 KB Output is correct
17 Correct 24 ms 6480 KB Output is correct
18 Correct 52 ms 13092 KB Output is correct
19 Correct 49 ms 14820 KB Output is correct
20 Correct 50 ms 14788 KB Output is correct
21 Correct 9 ms 4044 KB Output is correct
22 Correct 43 ms 13260 KB Output is correct
23 Correct 43 ms 12152 KB Output is correct
24 Correct 57 ms 14080 KB Output is correct
25 Correct 69 ms 14776 KB Output is correct
26 Correct 60 ms 14788 KB Output is correct
27 Correct 56 ms 14816 KB Output is correct
28 Correct 60 ms 14828 KB Output is correct
29 Correct 90 ms 14752 KB Output is correct
30 Correct 64 ms 14696 KB Output is correct
31 Correct 71 ms 14788 KB Output is correct
32 Correct 71 ms 14860 KB Output is correct
33 Correct 115 ms 14792 KB Output is correct
34 Correct 112 ms 14824 KB Output is correct
35 Correct 74 ms 11372 KB Output is correct
36 Correct 32 ms 8780 KB Output is correct
37 Correct 123 ms 14628 KB Output is correct
38 Correct 128 ms 15356 KB Output is correct
39 Correct 122 ms 15220 KB Output is correct
40 Correct 118 ms 15172 KB Output is correct
41 Correct 120 ms 15176 KB Output is correct
42 Correct 65 ms 15268 KB Output is correct
43 Correct 63 ms 15092 KB Output is correct
44 Correct 58 ms 15172 KB Output is correct
45 Correct 142 ms 15124 KB Output is correct
46 Correct 147 ms 15144 KB Output is correct
47 Correct 923 ms 84132 KB Output is correct
48 Correct 791 ms 156512 KB Output is correct
49 Correct 924 ms 170904 KB Output is correct
50 Correct 963 ms 187648 KB Output is correct
51 Execution timed out 1095 ms 201900 KB Time limit exceeded
52 Halted 0 ms 0 KB -