Submission #228916

#TimeUsernameProblemLanguageResultExecution timeMemory
228916alishahali1382Jakarta Skyscrapers (APIO15_skyscraper)C++14
22 / 100
123 ms154360 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O2") #pragma GCC optimize ("unroll-loops") //#pragma GCC optimize("no-stack-protector,fast-math") using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<pii, int> piii; typedef pair<ll, ll> pll; #define debug(x) cerr<<#x<<'='<<(x)<<endl; #define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl; #define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl; #define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;} #define all(x) x.begin(), x.end() #define pb push_back #define kill(x) return cout<<x<<'\n', 0; const ld eps=1e-7; const int inf=1000000010; const ll INF=10000000000000010LL; const int mod=1000000007; const int SQ=180, MAXN=180*30000; int n, m, k, u, v, x, y, t, a, b, ans; int B[MAXN], P[MAXN]; int dist[MAXN]; bool mark[MAXN]; vector<pii> G[MAXN]; priority_queue<pii, vector<pii>, greater<pii>> pq; inline void addedge(int v1, int j1, int v2, int j2, int w){ G[v1*SQ+j1].pb({v2*SQ+j2, w}); } int main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); memset(dist, 63, sizeof(dist)); cin>>n>>m; for (int i=0; i<n; i++) for (int j=1; j<SQ; j++){ if (i>=j) addedge(i, j, i-j, j, 1); if (i+j<n) addedge(i, j, i+j, j, 1); addedge(i, j, i, 0, 0); } for (int i=0; i<m; i++){ cin>>B[i]>>P[i]; if (P[i]<SQ) G[B[i]*SQ].pb({B[i]*SQ+P[i], 0}); else{ for (int j=1; B[i]-j*SQ>=0; j++) G[B[i]*SQ].pb({(B[i]-j*SQ)*SQ, j}); for (int j=1; B[i]+j*SQ<n; j++) G[B[i]*SQ].pb({(B[i]+j*SQ)*SQ, j}); } } pq.push({dist[B[0]*SQ]=0, B[0]*SQ}); while (pq.size()){ int v=pq.top().second; pq.pop(); if (mark[v]) continue ; mark[v]=1; for (pii p:G[v]) if (dist[p.first]>dist[v]+p.second) pq.push({dist[p.first]=dist[v]+p.second, p.first}); } ans=dist[SQ*B[1]]; if (ans>=inf) ans=-1; cout<<ans<<'\n'; 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...