Submission #975488

# Submission time Handle Problem Language Result Execution time Memory
975488 2024-05-05T10:07:19 Z batsukh2006 Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
561 ms 4044 KB
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
#include<string.h>
#include<utility>
#include<set>
#include<cmath>
#include<queue>
#include<deque>
#include<functional>
#include<stack>
#include<limits.h>
#include<iomanip>
#include<unordered_map> 
#include<numeric>
#include<tuple>
using namespace std;
 
#define MOD 1000000009
//#define int long long
#define ff first
#define ss second
#define endl '\n'
typedef pair<int,int> pp;
void solve(){
	int n,m; cin>>n>>m;
	int st,ed;
	vector<int> v[n];
	for(int i=0; i<m; i++){
		int b,p; cin>>b>>p;
		if(i==0) st=b;
		if(i==1) ed=b;
		v[b].push_back(p);
	}
	priority_queue<pp,vector<pp>,greater<pp> > q;
	vector<int> dis(n,1e9);
	q.push({0,st});
	dis[st]=0;
	while(!q.empty()){
		int d=q.top().ff;
		int c=q.top().ss;
		q.pop();
		if(d<=dis[c]){
			for(auto p: v[c]){
				for(int i=c,k=0; i<n; i+=p,k++){
					if(d+k<dis[i]){
						dis[i]=d+k;
						q.push({d+k,i});
					}
				}
				for(int i=c,k=0; i>=0; i-=p,k++){
					if(d+k<dis[i]){
						dis[i]=d+k;
						q.push({d+k,i});
					}
				}
			}
		}
	}
	if(dis[ed]!=1e9) cout<<dis[ed];
	else cout<<-1;
}
signed main(){
    // freopen("248.in", "r", stdin);
    // freopen("248.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int t=1;
//    cin>>t;	
    while(t--){
        solve();
        cout<<endl;
    }
    return 0;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Compilation message

skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:64:11: warning: 'ed' may be used uninitialized in this function [-Wmaybe-uninitialized]
   64 |  if(dis[ed]!=1e9) cout<<dis[ed];
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 452 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 404 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 500 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 4 ms 604 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 6 ms 552 KB Output is correct
27 Correct 4 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 484 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 456 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 500 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 4 ms 348 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 5 ms 860 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 5 ms 860 KB Output is correct
38 Correct 9 ms 1116 KB Output is correct
39 Correct 6 ms 860 KB Output is correct
40 Correct 6 ms 976 KB Output is correct
41 Correct 6 ms 976 KB Output is correct
42 Correct 41 ms 860 KB Output is correct
43 Correct 41 ms 860 KB Output is correct
44 Correct 46 ms 908 KB Output is correct
45 Correct 6 ms 1116 KB Output is correct
46 Correct 6 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 352 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 352 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
16 Correct 0 ms 352 KB Output is correct
17 Correct 1 ms 352 KB Output is correct
18 Correct 1 ms 360 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 3 ms 600 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 460 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 4 ms 344 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 2 ms 656 KB Output is correct
30 Correct 1 ms 456 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 4 ms 860 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 4 ms 860 KB Output is correct
38 Correct 6 ms 1088 KB Output is correct
39 Correct 6 ms 860 KB Output is correct
40 Correct 5 ms 1116 KB Output is correct
41 Correct 6 ms 976 KB Output is correct
42 Correct 41 ms 856 KB Output is correct
43 Correct 40 ms 860 KB Output is correct
44 Correct 43 ms 928 KB Output is correct
45 Correct 5 ms 1116 KB Output is correct
46 Correct 5 ms 1116 KB Output is correct
47 Correct 12 ms 2008 KB Output is correct
48 Correct 4 ms 1628 KB Output is correct
49 Correct 5 ms 1668 KB Output is correct
50 Correct 3 ms 1628 KB Output is correct
51 Correct 19 ms 3224 KB Output is correct
52 Correct 18 ms 2776 KB Output is correct
53 Correct 10 ms 2776 KB Output is correct
54 Correct 2 ms 1372 KB Output is correct
55 Correct 2 ms 1620 KB Output is correct
56 Correct 548 ms 2772 KB Output is correct
57 Correct 34 ms 3536 KB Output is correct
58 Correct 530 ms 1628 KB Output is correct
59 Correct 561 ms 1880 KB Output is correct
60 Correct 560 ms 1880 KB Output is correct
61 Correct 526 ms 1884 KB Output is correct
62 Correct 7 ms 2340 KB Output is correct
63 Correct 25 ms 2772 KB Output is correct
64 Correct 24 ms 4044 KB Output is correct
65 Correct 29 ms 3792 KB Output is correct
66 Correct 44 ms 3792 KB Output is correct
67 Correct 43 ms 3792 KB Output is correct