# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
995452 | 2024-06-09T06:13:25 Z | Baytoro | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 15 ms | 5152 KB |
#include <bits/stdc++.h> using namespace std; #define fr first #define sc second #define pb push_back //#define int long long #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } #define ll long long const int N=3e4+5; vector<int> g[N]; int n,m; bool used[2005][2005]; int distnce[2005]; void bfs(int x){ queue<pair<int,pair<int,int> > > dq; for(auto it: g[x]){ dq.push(make_pair(it,make_pair(x,0))); used[x][it]=1; } while(!dq.empty()){ int p=dq.front().fr; int d=dq.front().sc.fr; int dist=dq.front().sc.sc; dq.pop(); if(d+p<n){ if(!used[d+p][p]){ dq.push(make_pair(p,make_pair(d+p,dist+1))); distnce[d+p]=min(dist+1,distnce[d+p]); used[d+p][p]=1; } } if(d-p>=0){ if(!used[d-p][p]){ dq.push(make_pair(p,make_pair(d-p,dist+1))); distnce[d-p]=min(dist+1,distnce[d-p]); used[d-p][p]=1; } } for(auto it: g[d]){ if(!used[d][it]){ dq.push(make_pair(it,make_pair(d,dist))); used[d][it]=1; } } } } void solve(){ for(int i=0;i<2005;i++) distnce[i]=1e9; cin>>n>>m; vector<int> b(m),p(m); for(int i=0;i<m;i++){ cin>>b[i]>>p[i]; g[b[i]].pb(p[i]); } distnce[b[0]]=0; bfs(b[0]); if(distnce[b[1]]>1e8) cout<<-1<<endl; else{ cout<<distnce[b[1]]<<endl; } } signed main(){ //fopn("paint"); int t=1;//cin>>t; while(t--) solve(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1116 KB | Output is correct |
2 | Correct | 1 ms | 1400 KB | Output is correct |
3 | Correct | 1 ms | 1116 KB | Output is correct |
4 | Correct | 1 ms | 1164 KB | Output is correct |
5 | Correct | 0 ms | 1116 KB | Output is correct |
6 | Correct | 0 ms | 1116 KB | Output is correct |
7 | Correct | 1 ms | 1116 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1112 KB | Output is correct |
2 | Correct | 1 ms | 1116 KB | Output is correct |
3 | Correct | 1 ms | 1156 KB | Output is correct |
4 | Correct | 1 ms | 1116 KB | Output is correct |
5 | Correct | 1 ms | 1368 KB | Output is correct |
6 | Correct | 1 ms | 1116 KB | Output is correct |
7 | Correct | 1 ms | 1116 KB | Output is correct |
8 | Correct | 0 ms | 1116 KB | Output is correct |
9 | Correct | 0 ms | 1116 KB | Output is correct |
10 | Correct | 1 ms | 1372 KB | Output is correct |
11 | Correct | 1 ms | 1372 KB | Output is correct |
12 | Correct | 1 ms | 1372 KB | Output is correct |
13 | Correct | 1 ms | 1372 KB | Output is correct |
14 | Correct | 1 ms | 1372 KB | Output is correct |
15 | Correct | 1 ms | 1372 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1116 KB | Output is correct |
2 | Correct | 0 ms | 1116 KB | Output is correct |
3 | Correct | 0 ms | 1116 KB | Output is correct |
4 | Correct | 1 ms | 1116 KB | Output is correct |
5 | Correct | 1 ms | 1116 KB | Output is correct |
6 | Correct | 1 ms | 1116 KB | Output is correct |
7 | Correct | 1 ms | 1116 KB | Output is correct |
8 | Correct | 1 ms | 1116 KB | Output is correct |
9 | Correct | 1 ms | 1116 KB | Output is correct |
10 | Correct | 1 ms | 1116 KB | Output is correct |
11 | Correct | 1 ms | 1428 KB | Output is correct |
12 | Correct | 1 ms | 1372 KB | Output is correct |
13 | Correct | 1 ms | 1372 KB | Output is correct |
14 | Correct | 1 ms | 1372 KB | Output is correct |
15 | Correct | 1 ms | 1372 KB | Output is correct |
16 | Correct | 1 ms | 1116 KB | Output is correct |
17 | Correct | 2 ms | 2468 KB | Output is correct |
18 | Correct | 1 ms | 1116 KB | Output is correct |
19 | Correct | 1 ms | 1116 KB | Output is correct |
20 | Correct | 3 ms | 4956 KB | Output is correct |
21 | Correct | 1 ms | 1116 KB | Output is correct |
22 | Correct | 1 ms | 1116 KB | Output is correct |
23 | Correct | 3 ms | 4188 KB | Output is correct |
24 | Correct | 3 ms | 4808 KB | Output is correct |
25 | Correct | 3 ms | 4956 KB | Output is correct |
26 | Correct | 3 ms | 5044 KB | Output is correct |
27 | Correct | 3 ms | 4956 KB | Output is correct |
28 | Correct | 4 ms | 4956 KB | Output is correct |
29 | Correct | 3 ms | 5080 KB | Output is correct |
30 | Correct | 2 ms | 4956 KB | Output is correct |
31 | Correct | 3 ms | 4956 KB | Output is correct |
32 | Correct | 3 ms | 4956 KB | Output is correct |
33 | Correct | 4 ms | 5144 KB | Output is correct |
34 | Correct | 4 ms | 5152 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1116 KB | Output is correct |
2 | Correct | 1 ms | 1116 KB | Output is correct |
3 | Correct | 1 ms | 1116 KB | Output is correct |
4 | Correct | 0 ms | 1116 KB | Output is correct |
5 | Correct | 1 ms | 1116 KB | Output is correct |
6 | Correct | 1 ms | 1116 KB | Output is correct |
7 | Correct | 1 ms | 1160 KB | Output is correct |
8 | Correct | 1 ms | 1116 KB | Output is correct |
9 | Correct | 1 ms | 1116 KB | Output is correct |
10 | Correct | 1 ms | 1372 KB | Output is correct |
11 | Correct | 1 ms | 1372 KB | Output is correct |
12 | Correct | 1 ms | 1372 KB | Output is correct |
13 | Correct | 1 ms | 1372 KB | Output is correct |
14 | Correct | 1 ms | 1372 KB | Output is correct |
15 | Correct | 1 ms | 1368 KB | Output is correct |
16 | Correct | 1 ms | 1112 KB | Output is correct |
17 | Correct | 2 ms | 2652 KB | Output is correct |
18 | Correct | 1 ms | 1112 KB | Output is correct |
19 | Correct | 1 ms | 1116 KB | Output is correct |
20 | Correct | 3 ms | 4956 KB | Output is correct |
21 | Correct | 1 ms | 1116 KB | Output is correct |
22 | Correct | 1 ms | 1116 KB | Output is correct |
23 | Correct | 2 ms | 4188 KB | Output is correct |
24 | Correct | 4 ms | 4956 KB | Output is correct |
25 | Correct | 4 ms | 4956 KB | Output is correct |
26 | Correct | 3 ms | 4968 KB | Output is correct |
27 | Correct | 3 ms | 4952 KB | Output is correct |
28 | Correct | 4 ms | 4956 KB | Output is correct |
29 | Correct | 4 ms | 5072 KB | Output is correct |
30 | Correct | 3 ms | 4956 KB | Output is correct |
31 | Correct | 3 ms | 4956 KB | Output is correct |
32 | Correct | 3 ms | 4928 KB | Output is correct |
33 | Correct | 5 ms | 4956 KB | Output is correct |
34 | Correct | 4 ms | 4956 KB | Output is correct |
35 | Correct | 14 ms | 4700 KB | Output is correct |
36 | Incorrect | 4 ms | 3420 KB | Output isn't correct |
37 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1116 KB | Output is correct |
2 | Correct | 0 ms | 1116 KB | Output is correct |
3 | Correct | 0 ms | 1116 KB | Output is correct |
4 | Correct | 1 ms | 1116 KB | Output is correct |
5 | Correct | 0 ms | 1116 KB | Output is correct |
6 | Correct | 0 ms | 1116 KB | Output is correct |
7 | Correct | 0 ms | 1116 KB | Output is correct |
8 | Correct | 1 ms | 1116 KB | Output is correct |
9 | Correct | 1 ms | 1116 KB | Output is correct |
10 | Correct | 1 ms | 1116 KB | Output is correct |
11 | Correct | 1 ms | 1372 KB | Output is correct |
12 | Correct | 1 ms | 1372 KB | Output is correct |
13 | Correct | 1 ms | 1372 KB | Output is correct |
14 | Correct | 1 ms | 1372 KB | Output is correct |
15 | Correct | 2 ms | 1372 KB | Output is correct |
16 | Correct | 1 ms | 1116 KB | Output is correct |
17 | Correct | 2 ms | 2652 KB | Output is correct |
18 | Correct | 1 ms | 1116 KB | Output is correct |
19 | Correct | 1 ms | 1116 KB | Output is correct |
20 | Correct | 3 ms | 4956 KB | Output is correct |
21 | Correct | 1 ms | 1184 KB | Output is correct |
22 | Correct | 1 ms | 1116 KB | Output is correct |
23 | Correct | 3 ms | 4184 KB | Output is correct |
24 | Correct | 4 ms | 4752 KB | Output is correct |
25 | Correct | 3 ms | 5064 KB | Output is correct |
26 | Correct | 3 ms | 4956 KB | Output is correct |
27 | Correct | 3 ms | 4956 KB | Output is correct |
28 | Correct | 4 ms | 4956 KB | Output is correct |
29 | Correct | 3 ms | 4956 KB | Output is correct |
30 | Correct | 2 ms | 4960 KB | Output is correct |
31 | Correct | 3 ms | 4940 KB | Output is correct |
32 | Correct | 3 ms | 5004 KB | Output is correct |
33 | Correct | 4 ms | 4952 KB | Output is correct |
34 | Correct | 4 ms | 4956 KB | Output is correct |
35 | Correct | 15 ms | 4700 KB | Output is correct |
36 | Incorrect | 4 ms | 3420 KB | Output isn't correct |
37 | Halted | 0 ms | 0 KB | - |