Submission #730832

#TimeUsernameProblemLanguageResultExecution timeMemory
730832Jarif_RahmanJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1075 ms4176 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const int inf = 1e9, N = 30000; int B[N], P[N]; vector<int> residents[N]; bitset<N> bl; int dis[N]; vector<int> Q[N+1]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for(int i = 0; i < m; i++){ cin >> B[i] >> P[i]; residents[B[i]].pb(i); } fill(dis, dis+m, inf); for(int x: residents[B[0]]) Q[0].pb(x); for(int d = 0; d <= N; d++) for(int nd: Q[d]){ if(nd == 1){ cout << d << "\n"; exit(0); } if(bl[nd]) continue; bl[nd] = 1; for(int i = B[nd]+P[nd], dd = d+1; i < n; i+=P[nd], dd++) for(int x: residents[i]) if(dd < dis[x]){ dis[x] = dd; Q[dd].pb(x); } for(int i = B[nd]-P[nd], dd = d+1; i >= 0; i-=P[nd], dd++) for(int x: residents[i]) if(dd < dis[x]){ dis[x] = dd; Q[dd].pb(x); } } cout << "-1\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...