제출 #874478

#제출 시각아이디문제언어결과실행 시간메모리
874478arashMLGJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
90 ms127504 KiB
#include<bits/stdc++.h> #ifdef LOCAL #include "Essentials/algo/debug.h" #else #define debug(...) 69 #endif using namespace std; typedef long long ll; typedef pair<short,short> pii; const int N = 2e3 + 23; const int M = 3e4 + 23; const ll inf = 1e18; #define F first #define S second #define pb push_back #define kill(x) cout<<x<<endl, exit(0); #define all(x) x.begin(),x.end() #define sz(x) (int)x.size() #define lc (v << 1) #define rc ((v<<1) |1) #define int short #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") int n,m; vector<int> here[N]; bool vis[N]; bitset<N> mark[M]; deque<pii> dq; int dist[M][N]; int b[M],p[M]; void bfs() { mark[0][b[0]] = 1; dq.push_front({0,b[0]}); while(sz(dq)) { auto [id,pos] = dq.front(); dq.pop_front(); if(id == 1) { kill(dist[id][pos]); } if(!vis[pos]) { for(int x : here[pos]) { if(!mark[x][pos]) { mark[x][pos] = 1; dist[x][pos] = dist[id][pos]; dq.push_front({x,pos}); } } vis[pos] = true; } // front if(pos+ p[id] < n && !mark[id][pos + p[id]]) { mark[id][pos + p[id]] = true; dist[id][pos + p[id]] = dist[id][pos] + 1; dq.push_back({id,pos + p[id]}); } // back if(pos- p[id] >=0 && !mark[id][pos - p[id]]) { mark[id][pos - p[id]] = true; dist[id][pos - p[id]] = dist[id][pos] + 1; dq.push_back({id,pos - p[id]}); } } } int32_t main() { cin.tie(nullptr)->sync_with_stdio(false); cin>>n>>m; for(int i = 0 ; i <m; i++) { cin>>b[i]>>p[i]; here[b[i]].pb(i); } bfs(); kill(-1); return 0; }
#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...